ltec 0.1.2.1 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/exe/ltectool +2 -2
- data/lib/ltec/version.rb +1 -1
- data/lib/ltec.rb +37 -5
- data/lib/test.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7ce0a8046af3c372c5d9747dfd683b81c3932c140bc6def663e8a2e906c40d06
|
4
|
+
data.tar.gz: 2c4ba23adb846477de6e15626b25f691f6ebcb2c024786fdb5668a028345d4db
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0c587741da4cf932e833ffa0f02ac0fa72b602bf53350f1fcad7ff87a798f97a5eab215cb9019ccb8c6b0fce532ee062e9e92e7d7e79eca2af377afdde4a8f85
|
7
|
+
data.tar.gz: f9a4ece61730d029d94f2bd8431c4de373360d908694cc12fa49ff77449cb7c634e46085e8b4595baacc8c7017cb8117e05c8f03be25f23c9cf54f27b1cbb767
|
data/Gemfile.lock
CHANGED
data/exe/ltectool
CHANGED
@@ -15,7 +15,7 @@ require "ltec"
|
|
15
15
|
cmd = ARGV[0]
|
16
16
|
|
17
17
|
if cmd == 'g'
|
18
|
-
kp = Ltec::EC.generateKeyPair()
|
18
|
+
kp = Ltec::EC.generateKeyPair(ARGV[1])
|
19
19
|
puts "publickey: #{kp['pubkey']}"
|
20
20
|
puts "privatekey: #{kp['seckey']}"
|
21
21
|
elsif cmd == 'e'
|
@@ -33,7 +33,7 @@ else
|
|
33
33
|
puts <<EOF
|
34
34
|
ltectool cmd [options]
|
35
35
|
commands
|
36
|
-
g
|
36
|
+
g [privateKey] generate key pair
|
37
37
|
e publickey message
|
38
38
|
d privatekey message
|
39
39
|
|
data/lib/ltec/version.rb
CHANGED
data/lib/ltec.rb
CHANGED
@@ -28,11 +28,43 @@ module Ltec
|
|
28
28
|
return base64.unpack("m*")[0].unpack('H*')[0]
|
29
29
|
end
|
30
30
|
|
31
|
-
def EC.generateKeyPair()
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
31
|
+
def EC.generateKeyPair(inputSecKey)
|
32
|
+
if inputSecKey
|
33
|
+
puts "generate key pair from secret key"
|
34
|
+
if inputSecKey.length < 44 # 32 byte
|
35
|
+
throw "secret key length error ,it's 32 "
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
ec = OpenSSL::PKey::EC.new(SECP256K1)
|
40
|
+
pubNum = OpenSSL::BN.new("1",16)
|
41
|
+
tmpPt = OpenSSL::PKey::EC::Point.new(ec.group)
|
42
|
+
|
43
|
+
priKey = OpenSSL::BN.new(toHex(base64Decode(inputSecKey)),16)
|
44
|
+
|
45
|
+
maxStr = 'FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141'
|
46
|
+
OpenSSL
|
47
|
+
max = OpenSSL::BN.new(maxStr,16)
|
48
|
+
if priKey >= max
|
49
|
+
throw "Private Key must be smaller than #{maxStr}"
|
50
|
+
end
|
51
|
+
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
pubPt = tmpPt.mul(0,priKey)
|
56
|
+
hexpt = pubPt.to_bn(:compressed).to_s(16)
|
57
|
+
pub64 = hexToBase64(hexpt)
|
58
|
+
|
59
|
+
return {"seckey" => inputSecKey.strip,"pubkey" => pub64.strip}
|
60
|
+
else
|
61
|
+
puts 'create New key pair'
|
62
|
+
ec1 = OpenSSL::PKey::EC.generate(SECP256K1)
|
63
|
+
seckey = EC.hexToBase64(ec1.private_key.to_s(16))
|
64
|
+
pubkey = EC.hexToBase64(ec1.public_key.to_bn(:compressed).to_s(16))
|
65
|
+
return {"seckey" => seckey.strip,"pubkey" => pubkey.strip}
|
66
|
+
end
|
67
|
+
|
36
68
|
end
|
37
69
|
|
38
70
|
def EC.encrypt(pubKey,msg)
|
data/lib/test.rb
CHANGED
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.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- vitock
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-06-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: openssl
|