ltec 0.1.3.1 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +5 -6
- data/exe/ltectool +17 -0
- data/lib/ltec/version.rb +1 -1
- data/lib/ltec.rb +55 -0
- data/t.rb +3 -0
- metadata +6 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0ba1216958d55a024ab2d7921832080690079b9e65f4fd8568f7af9768d51ef6
|
4
|
+
data.tar.gz: 933e4acfa9a12dac356f6e32588e28b38939b5e66c89ed0e6b8528b5384f7adc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7e0d884c1e9d5e6d6bade2fe804e1e2586b07521aebbf2c84903ae524690f11bd8fbbb1b9f8f3cccb3e0e785fef1a13e4d4f16b7c6043567f78e34a6ee55a7db
|
7
|
+
data.tar.gz: 8932566b6f612fce572a89ab4a5afd2ab26bfb27f6c1baa04f93b48b8c6cb96934ff03974f51ab1723a7631b07e90b82ff2d395624da538cca3ee38985ef1fd8
|
data/Gemfile.lock
CHANGED
@@ -1,23 +1,22 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
ltec (0.1.3)
|
5
|
-
base64 (~> 0.1.0)
|
4
|
+
ltec (0.1.3.1)
|
6
5
|
openssl
|
7
6
|
|
8
7
|
GEM
|
9
8
|
remote: https://gems.ruby-china.com/
|
10
9
|
specs:
|
11
|
-
|
12
|
-
|
13
|
-
rake (13.0.6)
|
10
|
+
openssl (3.3.0)
|
11
|
+
rake (13.2.1)
|
14
12
|
|
15
13
|
PLATFORMS
|
16
14
|
arm64-darwin-22
|
15
|
+
ruby
|
17
16
|
|
18
17
|
DEPENDENCIES
|
19
18
|
ltec!
|
20
19
|
rake (~> 13.0)
|
21
20
|
|
22
21
|
BUNDLED WITH
|
23
|
-
2.
|
22
|
+
2.5.23
|
data/exe/ltectool
CHANGED
@@ -28,6 +28,16 @@ elsif cmd == 'd'
|
|
28
28
|
enc = ARGV[2]
|
29
29
|
msg = Ltec::EC.decrypt(prikey,enc)
|
30
30
|
puts msg
|
31
|
+
elsif cmd == 'd64'
|
32
|
+
prikey = ARGV[1]
|
33
|
+
enc = ARGV[2]
|
34
|
+
msg = Ltec::EC.xDec(prikey,enc)
|
35
|
+
puts msg
|
36
|
+
elsif cmd == 'e64'
|
37
|
+
pubkey = ARGV[1]
|
38
|
+
msg64 = ARGV[2]
|
39
|
+
msg = Ltec::EC.xEnc(pubkey,msg64)
|
40
|
+
puts msg
|
31
41
|
|
32
42
|
else
|
33
43
|
puts <<EOF
|
@@ -36,6 +46,13 @@ else
|
|
36
46
|
g [privateKey] generate key pair
|
37
47
|
e publickey message
|
38
48
|
d privatekey message
|
49
|
+
e64 publickey message64
|
50
|
+
d64 privatekey cipher64
|
51
|
+
|
52
|
+
|
53
|
+
--------------------
|
54
|
+
e.g.
|
55
|
+
ltectool d64 privateKey mesg64 | base64 -d
|
39
56
|
|
40
57
|
EOF
|
41
58
|
end
|
data/lib/ltec/version.rb
CHANGED
data/lib/ltec.rb
CHANGED
@@ -155,5 +155,60 @@ module Ltec
|
|
155
155
|
txt = encryptor.update(dataEnc) + encryptor.final
|
156
156
|
return txt
|
157
157
|
end
|
158
|
+
|
159
|
+
def EC.test()
|
160
|
+
puts 'hello R'
|
161
|
+
end
|
162
|
+
|
163
|
+
|
164
|
+
def EC.xDec(priKey,msg)
|
165
|
+
priHex = base64ToHex(priKey)
|
166
|
+
prN = OpenSSL::BN.new(priHex,16)
|
167
|
+
bfMsg = base64Decode(msg)
|
168
|
+
pub = bfMsg[0,33]
|
169
|
+
pubhex = toHex(pub)
|
170
|
+
|
171
|
+
|
172
|
+
|
173
|
+
pubNum = OpenSSL::BN.new(pubhex,16)
|
174
|
+
curve = OpenSSL::PKey::EC::Group.new(SECP256K1)
|
175
|
+
ptPub = OpenSSL::PKey::EC::Point.new(curve,pubNum)
|
176
|
+
|
177
|
+
ptDh = ptPub.mul(prN)
|
178
|
+
ptX = fromHex(ptDh.to_bn(:compressed).to_s(16))[1...33]
|
179
|
+
|
180
|
+
dhHash = OpenSSL::Digest.digest("SHA512", ptX)
|
181
|
+
encryptor = OpenSSL::Cipher::AES256.new(:CTR)
|
182
|
+
encryptor.decrypt
|
183
|
+
encryptor.key = dhHash[0...32]
|
184
|
+
encryptor.iv = dhHash[32...48]
|
185
|
+
|
186
|
+
|
187
|
+
EC.base64(encryptor.update(bfMsg[33..-1]) + encryptor.final)
|
188
|
+
end
|
189
|
+
def EC.xEnc(pubKey,msg64)
|
190
|
+
msg = base64Decode(msg64)
|
191
|
+
hex = base64ToHex(pubKey)
|
192
|
+
|
193
|
+
|
194
|
+
ec = OpenSSL::PKey::EC.new(SECP256K1)
|
195
|
+
curve = OpenSSL::PKey::EC::Group.new(SECP256K1)
|
196
|
+
kp = OpenSSL::PKey::EC::generate(curve)
|
197
|
+
pubNum = OpenSSL::BN.new(hex,16)
|
198
|
+
ptPub = OpenSSL::PKey::EC::Point.new(ec.group,pubNum)
|
199
|
+
|
200
|
+
rndBn = kp.private_key.to_bn
|
201
|
+
ptTmp = kp.public_key
|
202
|
+
|
203
|
+
ptDh = ptPub.mul(rndBn)
|
204
|
+
ptX = fromHex(ptDh.to_bn(:compressed).to_s(16))[1...33]
|
205
|
+
|
206
|
+
dhHash = OpenSSL::Digest.digest("SHA512", ptX)
|
207
|
+
encryptor = OpenSSL::Cipher::AES256.new(:CTR)
|
208
|
+
encryptor.encrypt
|
209
|
+
encryptor.key = dhHash[0...32]
|
210
|
+
encryptor.iv = dhHash[32...48]
|
211
|
+
EC.base64( fromHex(ptTmp.to_bn(:compressed).to_s(16)) + encryptor.update(msg) + encryptor.final)
|
212
|
+
end
|
158
213
|
end
|
159
214
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ltec
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- vitock
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2025-01-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: openssl
|
@@ -24,20 +24,6 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: base64
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - "~>"
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: 0.1.0
|
34
|
-
type: :runtime
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - "~>"
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: 0.1.0
|
41
27
|
description: 'using ECC to enrypt private message with ruby ,the curve is SECP256k1 '
|
42
28
|
email:
|
43
29
|
- ''
|
@@ -55,13 +41,14 @@ files:
|
|
55
41
|
- lib/ltec/version.rb
|
56
42
|
- lib/test.rb
|
57
43
|
- sig/ltec.rbs
|
44
|
+
- t.rb
|
58
45
|
homepage: https://github.com/vitock/ltec_rb.git
|
59
46
|
licenses: []
|
60
47
|
metadata:
|
61
48
|
homepage_uri: https://github.com/vitock/ltec_rb.git
|
62
49
|
source_code_uri: https://github.com/vitock/ltec_rb.git
|
63
50
|
changelog_uri: https://github.com/vitock/ltec_rb/blob/master/README.md
|
64
|
-
post_install_message:
|
51
|
+
post_install_message:
|
65
52
|
rdoc_options: []
|
66
53
|
require_paths:
|
67
54
|
- lib
|
@@ -77,7 +64,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
77
64
|
version: '0'
|
78
65
|
requirements: []
|
79
66
|
rubygems_version: 3.2.33
|
80
|
-
signing_key:
|
67
|
+
signing_key:
|
81
68
|
specification_version: 4
|
82
69
|
summary: using ECC to enrypt private message
|
83
70
|
test_files: []
|