1
2
3
4 """PyCrypto RSA implementation."""
5
6 from .cryptomath import *
7
8 from .rsakey import *
9 from .python_rsakey import Python_RSAKey
10
11 if pycryptoLoaded:
12
13 from Crypto.PublicKey import RSA
14
16 - def __init__(self, n=0, e=0, d=0, p=0, q=0, dP=0, dQ=0, qInv=0):
17 if not d:
18 self.rsa = RSA.construct( (n, e) )
19 else:
20 self.rsa = RSA.construct( (n, e, d, p, q) )
21
23 return getattr(self.rsa, name)
24
26 return self.rsa.has_private()
27
29 s = numberToString(m, numBytes(self.n))
30 c = stringToNumber(self.rsa.decrypt((s,)))
31 return c
32
34 s = numberToString(c, numBytes(self.n))
35 m = stringToNumber(self.rsa.encrypt(s, None)[0])
36 return m
37
42 key.rsa = RSA.generate(bits, f)
43 return key
44 generate = staticmethod(generate)
45