OLD | NEW |
1 # Author: Trevor Perrin | 1 # Author: Trevor Perrin |
2 # See the LICENSE file for legal information regarding use of this file. | 2 # See the LICENSE file for legal information regarding use of this file. |
3 | 3 |
4 """Pure-Python RSA implementation.""" | 4 """Pure-Python RSA implementation.""" |
5 | 5 |
6 from .cryptomath import * | 6 from .cryptomath import * |
7 from .asn1parser import ASN1Parser | 7 from .asn1parser import ASN1Parser |
8 from .rsakey import * | 8 from .rsakey import * |
9 from .pem import * | 9 from .pem import * |
10 | 10 |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 key.d = invMod(key.e, t) | 77 key.d = invMod(key.e, t) |
78 key.p = p | 78 key.p = p |
79 key.q = q | 79 key.q = q |
80 key.dP = key.d % (p-1) | 80 key.dP = key.d % (p-1) |
81 key.dQ = key.d % (q-1) | 81 key.dQ = key.d % (q-1) |
82 key.qInv = invMod(q, p) | 82 key.qInv = invMod(q, p) |
83 return key | 83 return key |
84 generate = staticmethod(generate) | 84 generate = staticmethod(generate) |
85 | 85 |
86 def parsePEM(s, passwordCallback=None): | 86 def parsePEM(s, passwordCallback=None): |
87 """Parse a string containing a <privateKey> or <publicKey>, or | 87 """Parse a string containing a PEM-encoded <privateKey>.""" |
88 PEM-encoded key.""" | |
89 | 88 |
90 if pemSniff(s, "PRIVATE KEY"): | 89 if pemSniff(s, "PRIVATE KEY"): |
91 bytes = dePem(s, "PRIVATE KEY") | 90 bytes = dePem(s, "PRIVATE KEY") |
92 return Python_RSAKey._parsePKCS8(bytes) | 91 return Python_RSAKey._parsePKCS8(bytes) |
93 elif pemSniff(s, "RSA PRIVATE KEY"): | 92 elif pemSniff(s, "RSA PRIVATE KEY"): |
94 bytes = dePem(s, "RSA PRIVATE KEY") | 93 bytes = dePem(s, "RSA PRIVATE KEY") |
95 return Python_RSAKey._parseSSLeay(bytes) | 94 return Python_RSAKey._parseSSLeay(bytes) |
96 else: | 95 else: |
97 raise SyntaxError("Not a PEM private key file") | 96 raise SyntaxError("Not a PEM private key file") |
98 parsePEM = staticmethod(parsePEM) | 97 parsePEM = staticmethod(parsePEM) |
(...skipping 30 matching lines...) Expand all Loading... |
129 n = bytesToNumber(privateKeyP.getChild(1).value) | 128 n = bytesToNumber(privateKeyP.getChild(1).value) |
130 e = bytesToNumber(privateKeyP.getChild(2).value) | 129 e = bytesToNumber(privateKeyP.getChild(2).value) |
131 d = bytesToNumber(privateKeyP.getChild(3).value) | 130 d = bytesToNumber(privateKeyP.getChild(3).value) |
132 p = bytesToNumber(privateKeyP.getChild(4).value) | 131 p = bytesToNumber(privateKeyP.getChild(4).value) |
133 q = bytesToNumber(privateKeyP.getChild(5).value) | 132 q = bytesToNumber(privateKeyP.getChild(5).value) |
134 dP = bytesToNumber(privateKeyP.getChild(6).value) | 133 dP = bytesToNumber(privateKeyP.getChild(6).value) |
135 dQ = bytesToNumber(privateKeyP.getChild(7).value) | 134 dQ = bytesToNumber(privateKeyP.getChild(7).value) |
136 qInv = bytesToNumber(privateKeyP.getChild(8).value) | 135 qInv = bytesToNumber(privateKeyP.getChild(8).value) |
137 return Python_RSAKey(n, e, d, p, q, dP, dQ, qInv) | 136 return Python_RSAKey(n, e, d, p, q, dP, dQ, qInv) |
138 _parseASN1PrivateKey = staticmethod(_parseASN1PrivateKey) | 137 _parseASN1PrivateKey = staticmethod(_parseASN1PrivateKey) |
OLD | NEW |