lazy_rsa 0.3.4 → 0.3.6
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 +10 -3
- 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: aec4c9558e64d74ae8530e14ba5110cce7278010b4f80db751bfeb35e67bcdb4
|
4
|
+
data.tar.gz: ac1eae2fdaa2336001689e072746137aaad168d99c1253e7c885770ba5acfca6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ea9d42065fe7a1495369808a1d66695affa5d27009d4d9385e789f985479fc848ee289ff917a9a026364a62b2441c44becdde8174e5b1f8a2681e4e307d99c99
|
7
|
+
data.tar.gz: 6800a222e1b068fd55e75924a3fd9a2480ce9a90302eabb605a8358e9dda64a6e179d3a59acac6aaddf88b3723c488d2b39fcbf6ef2fa8e2db799cef36690c95
|
data/lib/lazy_rsa.rb
CHANGED
@@ -18,9 +18,10 @@ module LazyRsa
|
|
18
18
|
def generate_key
|
19
19
|
q = OpenSSL::BN.generate_prime(512)
|
20
20
|
phi = OpenSSL::BN.new(0)
|
21
|
-
|
21
|
+
loop do
|
22
22
|
p = OpenSSL::BN.generate_prime(512)
|
23
23
|
phi = (p - 1) * (q - 1)
|
24
|
+
break if q.gcd(phi) == 1
|
24
25
|
end
|
25
26
|
n = p * q
|
26
27
|
e = p.mod_exp(SECURE_EXPONENT, SECURE_MODULUS)
|
@@ -31,9 +32,15 @@ module LazyRsa
|
|
31
32
|
|
32
33
|
def build_key(e: nil, d: nil, n:)
|
33
34
|
data_sequence = OpenSSL::ASN1::Sequence([
|
35
|
+
OpenSSL::ASN1::Integer.new(0),
|
34
36
|
OpenSSL::ASN1::Integer(n),
|
35
|
-
OpenSSL::ASN1::Integer(e),
|
36
|
-
OpenSSL::ASN1::Integer(d),
|
37
|
+
e.nil? ? OpenSSL::ASN1::Integer.new(0) : OpenSSL::ASN1::Integer(e),
|
38
|
+
d.nil? ? OpenSSL::ASN1::Integer.new(0) : OpenSSL::ASN1::Integer(d),
|
39
|
+
OpenSSL::ASN1::Integer.new(0),
|
40
|
+
OpenSSL::ASN1::Integer.new(0),
|
41
|
+
OpenSSL::ASN1::Integer.new(0),
|
42
|
+
OpenSSL::ASN1::Integer.new(0),
|
43
|
+
OpenSSL::ASN1::Integer.new(0),
|
37
44
|
])
|
38
45
|
asn1 = OpenSSL::ASN1::Sequence(data_sequence)
|
39
46
|
OpenSSL::PKey::RSA.new(asn1.to_der)
|