ltec 0.1.3 → 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 +2 -1
- data/Gemfile.lock +8 -11
- data/exe/ltectool +17 -0
- data/lib/ltec/version.rb +1 -1
- data/lib/ltec.rb +55 -0
- data/t.rb +3 -0
- metadata +8 -22
- data/ltec.gemspec +0 -42
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
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,25 +1,22 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
ltec (0.1.3)
|
5
|
-
|
6
|
-
openssl (~> 2.2.0)
|
4
|
+
ltec (0.1.3.1)
|
5
|
+
openssl
|
7
6
|
|
8
7
|
GEM
|
9
|
-
remote: https://
|
8
|
+
remote: https://gems.ruby-china.com/
|
10
9
|
specs:
|
11
|
-
|
12
|
-
|
13
|
-
openssl (2.2.1)
|
14
|
-
ipaddr
|
15
|
-
rake (13.0.6)
|
10
|
+
openssl (3.3.0)
|
11
|
+
rake (13.2.1)
|
16
12
|
|
17
13
|
PLATFORMS
|
18
|
-
|
14
|
+
arm64-darwin-22
|
15
|
+
ruby
|
19
16
|
|
20
17
|
DEPENDENCIES
|
21
18
|
ltec!
|
22
19
|
rake (~> 13.0)
|
23
20
|
|
24
21
|
BUNDLED WITH
|
25
|
-
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,43 +1,29 @@
|
|
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
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
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: '0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
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
|
26
|
+
version: '0'
|
41
27
|
description: 'using ECC to enrypt private message with ruby ,the curve is SECP256k1 '
|
42
28
|
email:
|
43
29
|
- ''
|
@@ -54,8 +40,8 @@ files:
|
|
54
40
|
- lib/ltec.rb
|
55
41
|
- lib/ltec/version.rb
|
56
42
|
- lib/test.rb
|
57
|
-
- ltec.gemspec
|
58
43
|
- sig/ltec.rbs
|
44
|
+
- t.rb
|
59
45
|
homepage: https://github.com/vitock/ltec_rb.git
|
60
46
|
licenses: []
|
61
47
|
metadata:
|
@@ -77,7 +63,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
77
63
|
- !ruby/object:Gem::Version
|
78
64
|
version: '0'
|
79
65
|
requirements: []
|
80
|
-
rubygems_version: 3.2.
|
66
|
+
rubygems_version: 3.2.33
|
81
67
|
signing_key:
|
82
68
|
specification_version: 4
|
83
69
|
summary: using ECC to enrypt private message
|
data/ltec.gemspec
DELETED
@@ -1,42 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative "lib/ltec/version"
|
4
|
-
|
5
|
-
Gem::Specification.new do |spec|
|
6
|
-
spec.name = "ltec"
|
7
|
-
spec.version = Ltec::VERSION
|
8
|
-
spec.authors = ["vitock"]
|
9
|
-
spec.email = [""]
|
10
|
-
|
11
|
-
spec.summary = "using ECC to enrypt private message"
|
12
|
-
spec.description = "using ECC to enrypt private message with ruby ,the curve is SECP256k1 "
|
13
|
-
spec.homepage = "https://github.com/vitock/ltec_rb.git"
|
14
|
-
spec.required_ruby_version = ">= 2.6.0"
|
15
|
-
|
16
|
-
# spec.metadata["allowed_push_host"] = "TODO: Set to your gem server 'https://example.com'"
|
17
|
-
|
18
|
-
spec.metadata["homepage_uri"] = spec.homepage
|
19
|
-
spec.metadata["source_code_uri"] = "https://github.com/vitock/ltec_rb.git"
|
20
|
-
spec.metadata["changelog_uri"] = "https://github.com/vitock/ltec_rb/blob/master/README.md"
|
21
|
-
|
22
|
-
# Specify which files should be added to the gem when it is released.
|
23
|
-
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
24
|
-
spec.files = Dir.chdir(__dir__) do
|
25
|
-
`git ls-files -z`.split("\x0").reject do |f|
|
26
|
-
(f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
|
27
|
-
end
|
28
|
-
end
|
29
|
-
spec.bindir = "exe"
|
30
|
-
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
31
|
-
spec.require_paths = ["lib"]
|
32
|
-
|
33
|
-
# Uncomment to register a new dependency of your gem
|
34
|
-
# spec.add_dependency "example-gem", "~> 1.0"
|
35
|
-
|
36
|
-
spec.add_dependency "openssl", "~> 2.2.0"
|
37
|
-
spec.add_dependency "base64", "~> 0.1.0"
|
38
|
-
|
39
|
-
|
40
|
-
# For more information and examples about making a new gem, check out our
|
41
|
-
# guide at: https://bundler.io/guides/creating_gem.html
|
42
|
-
end
|