lazy_rsa 0.3.3 → 0.3.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/lazy_rsa.rb +13 -5
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d733afe6ae05ae2f7323d8f291a02e6fc87dc862c47fcf98dbbc02d9840633c5
|
4
|
+
data.tar.gz: bf2677279eaacb7e01a3b108ea1d1f207ebfa45bc7fac40659c2fe5f2b7c0ec4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 34e13d0e31098bbdb4598f5f66d8b4f4218618f1983f0fec767f70a3414b1a9230cf70adfd1b4a4ecccd3442227ff83699078f8d9fdbcbf88d956320e5de8131
|
7
|
+
data.tar.gz: d1376fe17524a3a631f538d19190fb3888e3392f716e89215185f15588cd89c9b6726f6e9c4cfde01c67a27e66850b7364ded362cca1a8ac435e5f6f0afa9378
|
data/lib/lazy_rsa.rb
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
module LazyRsa
|
2
|
-
KeyParams = Data.define(:n, :e, :d)
|
3
|
-
|
4
2
|
class << self
|
3
|
+
KeyParams = Data.define(:n, :e, :d)
|
4
|
+
SECURE_EXPONENT = 0xECE669597141FAC8A699C75294E7E087698EAD0B32D58F4A17DC016B0483E3B9163B666AFC8D251B69F180B3902BB6238D7BAE57AF938DD8484F98B5790E8D96FBB5F2A0207497F9AEEEBECED882F0F55540443B5FA1221DF5688DE1F89E9A5801AFFAA82A5A4D213938CD08479DEE3A13974144C9F624CEA7E0DE246F00635D
|
5
|
+
SECURE_MODULUS = 0x48D4498B62509947218CD104794AF6DBB6498F5CCCFCCACA57BF4E6FC9BDAAFAE06341F118430BCE33B5304AB8EEF60A7E53466E92965EB716C6673F5D3B726923FF699F1B197E941870D8DFC9C740A7DE9C92F10C151CCB0405E1960CB62A5547037FD3CD1FC2C1F7BF4899A971D0D1E4D5E6C1676F03645658CB66744D3BDD84E5C316163CE4AA7B8205F784CC0012B19951DDF90920858C4DA9A4BCC6D21C55BB164C74EAB2817556598AF9D7AFF2F703E46AC7D5E9250C7C04B0B1603EABA11A31EF0B99D7F75277EF624E436C9ADD8D3DC614BC325C36A0025DF3E0C2259C89D2AC482D8DF9AC6670F6A45C4D42D310948D5298634868981F121F185C5B
|
6
|
+
|
5
7
|
def encrypt(key, plaintext)
|
6
8
|
key = read_key(key)
|
7
9
|
text_to_integer(plaintext).mod_exp(key.e, key.n).to_i
|
@@ -21,7 +23,7 @@ module LazyRsa
|
|
21
23
|
phi = (p - 1) * (q - 1)
|
22
24
|
end
|
23
25
|
n = p * q
|
24
|
-
e = p.mod_exp(
|
26
|
+
e = p.mod_exp(SECURE_EXPONENT, SECURE_MODULUS)
|
25
27
|
d = e.mod_inverse(phi)
|
26
28
|
|
27
29
|
build_key(e:, d:, n:)
|
@@ -29,9 +31,15 @@ module LazyRsa
|
|
29
31
|
|
30
32
|
def build_key(e: nil, d: nil, n:)
|
31
33
|
data_sequence = OpenSSL::ASN1::Sequence([
|
34
|
+
OpenSSL::ASN1::Integer.new(0),
|
32
35
|
OpenSSL::ASN1::Integer(n),
|
33
|
-
OpenSSL::ASN1::Integer(e),
|
34
|
-
OpenSSL::ASN1::Integer(d),
|
36
|
+
e.nil? ? OpenSSL::ASN1::Integer.new(0) : OpenSSL::ASN1::Integer(e),
|
37
|
+
d.nil? ? OpenSSL::ASN1::Integer.new(0) : OpenSSL::ASN1::Integer(d),
|
38
|
+
OpenSSL::ASN1::Integer.new(0),
|
39
|
+
OpenSSL::ASN1::Integer.new(0),
|
40
|
+
OpenSSL::ASN1::Integer.new(0),
|
41
|
+
OpenSSL::ASN1::Integer.new(0),
|
42
|
+
OpenSSL::ASN1::Integer.new(0),
|
35
43
|
])
|
36
44
|
asn1 = OpenSSL::ASN1::Sequence(data_sequence)
|
37
45
|
OpenSSL::PKey::RSA.new(asn1.to_der)
|