ltec 0.1.1 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f8d26733395b3b78dc2ec834297af2fe7773acf8f4f3b9de6681f226b4d82fa3
4
- data.tar.gz: 1f37579b78dde51aa930d1cac9511837ee399dfd3924344e9f2ebff4f0032065
3
+ metadata.gz: 7ce0a8046af3c372c5d9747dfd683b81c3932c140bc6def663e8a2e906c40d06
4
+ data.tar.gz: 2c4ba23adb846477de6e15626b25f691f6ebcb2c024786fdb5668a028345d4db
5
5
  SHA512:
6
- metadata.gz: ff58f4e4698ca7f495627db0763cba642dbe60abd32583feb653dbbdc14e0cfa447c4d27ffc56977331cfe24098a5eec33cdd6f4b1f2a8d6df99551b583c2751
7
- data.tar.gz: 9d3b5eb65fd5bab11c43dafda2e83aa6586c0fa9038e5b05c79af41e9df5d1856b7702b50ad0f3f31c214c95452090e42774ea0052f46540f3c06ea842c6bd8b
6
+ metadata.gz: 0c587741da4cf932e833ffa0f02ac0fa72b602bf53350f1fcad7ff87a798f97a5eab215cb9019ccb8c6b0fce532ee062e9e92e7d7e79eca2af377afdde4a8f85
7
+ data.tar.gz: f9a4ece61730d029d94f2bd8431c4de373360d908694cc12fa49ff77449cb7c634e46085e8b4595baacc8c7017cb8117e05c8f03be25f23c9cf54f27b1cbb767
data/Gemfile.lock CHANGED
@@ -1,18 +1,18 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ltec (0.1.0)
4
+ ltec (0.1.3)
5
5
  base64 (~> 0.1.0)
6
6
  openssl (~> 2.2.0)
7
- salsa20 (~> 0.1.3)
8
7
 
9
8
  GEM
10
9
  remote: https://rubygems.org/
11
10
  specs:
12
- base64 (0.1.0)
13
- openssl (2.2.0)
14
- rake (13.0.3)
15
- salsa20 (0.1.3)
11
+ base64 (0.1.1)
12
+ ipaddr (1.2.4)
13
+ openssl (2.2.1)
14
+ ipaddr
15
+ rake (13.0.6)
16
16
 
17
17
  PLATFORMS
18
18
  x86_64-darwin-20
data/README.md CHANGED
@@ -3,6 +3,10 @@
3
3
  a tinny tool to encryt your private message via ECC(Secp256k1)
4
4
 
5
5
 
6
+ # upate 0.1.2
7
+ using AES instead of Salsa20
8
+
9
+
6
10
  ## Installation
7
11
 
8
12
  Install the gem and add to the application's Gemfile by executing:
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 generate key pair
36
+ g [privateKey] generate key pair
37
37
  e publickey message
38
38
  d privatekey message
39
39
 
data/lib/ltec/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Ltec
4
- VERSION = "0.1.1"
4
+ VERSION = "0.1.3"
5
5
  end
data/lib/ltec.rb CHANGED
@@ -3,7 +3,6 @@
3
3
  require_relative "ltec/version"
4
4
  require 'openssl'
5
5
  require "base64"
6
- require 'salsa20'
7
6
 
8
7
  module Ltec
9
8
  class Error < StandardError; end
@@ -29,11 +28,43 @@ module Ltec
29
28
  return base64.unpack("m*")[0].unpack('H*')[0]
30
29
  end
31
30
 
32
- def EC.generateKeyPair()
33
- ec1 = OpenSSL::PKey::EC.generate(SECP256K1)
34
- seckey = EC.hexToBase64(ec1.private_key.to_s(16))
35
- pubkey = EC.hexToBase64(ec1.public_key.to_bn(:compressed).to_s(16))
36
- return {"seckey" => seckey.strip,"pubkey" => pubkey.strip}
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
+
37
68
  end
38
69
 
39
70
  def EC.encrypt(pubKey,msg)
@@ -65,24 +96,34 @@ module Ltec
65
96
 
66
97
  dhHash = OpenSSL::Digest.digest("SHA512", ptX)
67
98
 
68
- nonce = OpenSSL::Random.random_bytes(8)
69
- encryptor = Salsa20.new(dhHash[0...32], nonce)
70
- encrypted_text = encryptor.encrypt(msg)
71
-
99
+ nonce = OpenSSL::Random.random_bytes(16)
100
+
101
+ encryptor = OpenSSL::Cipher::AES256.new(:CBC)
102
+ encryptor.encrypt
103
+ encryptor.key = dhHash[0...32]
104
+ encryptor.iv = nonce
105
+
106
+
107
+ # encryptor = Salsa20.new(dhHash[0...32], nonce)
108
+ encrypted_text = encryptor.update(msg) + encryptor.final
72
109
  dataforMac = nonce + empherPub + encrypted_text
73
110
  mac = OpenSSL::HMAC.digest('sha256', dhHash[32,64], dataforMac)
74
111
 
75
112
  #
76
- return base64(fromHex('0300080020002100') + nonce + mac + empherPub + encrypted_text)
113
+ return base64(fromHex('0100100020002100') + nonce + mac + empherPub + encrypted_text)
77
114
 
78
115
  end
79
116
 
80
117
  def EC.decrypt(secKey,base64Cipher)
81
118
  encResult = base64Decode(base64Cipher)
82
- nonce = encResult[8...16]
83
- mac = encResult[16...48]
84
- tmpPub = encResult[48...81]
85
- dataEnc = encResult[81...encResult.length]
119
+ start = 8
120
+ nonce = encResult[start...(start + 16)]
121
+ start = start + 16;
122
+ mac = encResult[start...(start + 32)]
123
+ start = start + 32;
124
+ tmpPub = encResult[start...(start + 33)]
125
+ start = start + 33;
126
+ dataEnc = encResult[start...(encResult.length)]
86
127
 
87
128
  tmpPubHex = toHex(tmpPub)
88
129
  ec = OpenSSL::PKey::EC.new(SECP256K1)
@@ -105,9 +146,13 @@ module Ltec
105
146
  if mac2 != mac
106
147
  raise 'Mac not Fit,the privateKey is not fit'
107
148
  end
108
-
109
- encryptor = Salsa20.new(key, nonce)
110
- txt = encryptor.decrypt(dataEnc)
149
+ # encryptor = Salsa20.new(key, nonce)
150
+ # txt = encryptor.decrypt(dataEnc)
151
+ encryptor = OpenSSL::Cipher::AES256.new(:CBC)
152
+ encryptor.decrypt
153
+ encryptor.key = key
154
+ encryptor.iv = nonce
155
+ txt = encryptor.update(dataEnc) + encryptor.final
111
156
  return txt
112
157
  end
113
158
  end
data/lib/test.rb ADDED
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "ltec"
4
+
5
+ kp = Ltec::EC.generateKeyPair(ARGV[0])
6
+ puts kp
7
+ msg = "hello"
8
+ msg2 = "hello world3"
9
+
10
+ enc1 = Ltec::EC.encrypt(kp['pubkey'],msg)
11
+ dec1 = Ltec::EC.decrypt(kp['seckey'],enc1)
12
+ puts enc1
13
+ puts dec1
14
+
15
+
16
+
17
+ enc2 = Ltec::EC.encrypt(kp['pubkey'],msg2)
18
+ dec2 = Ltec::EC.decrypt(kp['seckey'],enc2)
19
+ puts enc2
20
+ puts dec2
data/ltec.gemspec CHANGED
@@ -35,7 +35,6 @@ Gem::Specification.new do |spec|
35
35
 
36
36
  spec.add_dependency "openssl", "~> 2.2.0"
37
37
  spec.add_dependency "base64", "~> 0.1.0"
38
- spec.add_dependency "salsa20", "~> 0.1.3"
39
38
 
40
39
 
41
40
  # For more information and examples about making a new gem, check out our
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.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-05-13 00:00:00.000000000 Z
11
+ date: 2022-06-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: openssl
@@ -38,20 +38,6 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: 0.1.0
41
- - !ruby/object:Gem::Dependency
42
- name: salsa20
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - "~>"
46
- - !ruby/object:Gem::Version
47
- version: 0.1.3
48
- type: :runtime
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - "~>"
53
- - !ruby/object:Gem::Version
54
- version: 0.1.3
55
41
  description: 'using ECC to enrypt private message with ruby ,the curve is SECP256k1 '
56
42
  email:
57
43
  - ''
@@ -67,6 +53,7 @@ files:
67
53
  - exe/ltectool
68
54
  - lib/ltec.rb
69
55
  - lib/ltec/version.rb
56
+ - lib/test.rb
70
57
  - ltec.gemspec
71
58
  - sig/ltec.rbs
72
59
  homepage: https://github.com/vitock/ltec_rb.git