summaryrefslogtreecommitdiff
path: root/lib/Crypto/PublicKey/RSA.py
diff options
context:
space:
mode:
authorLegrandin <gooksankoo@hoiptorrow.mailexpire.com>2010-01-21 20:14:10 +0100
committerDwayne C. Litzenberger <dlitz@dlitz.net>2010-08-02 16:34:53 -0400
commit902ea14fc2d3d4a6e01afbef6f45115ab37e7fcd (patch)
tree927726c28e18157f95115bdcf83258b8ac7252c0 /lib/Crypto/PublicKey/RSA.py
parent0f45878cef67965dc39144b5536368d934d61589 (diff)
downloadpycrypto-902ea14fc2d3d4a6e01afbef6f45115ab37e7fcd.tar.gz
Support for older versions of python
This patch add support for older python 2.1/2.2 to the previous one (DER/PEM). Committer: Legrandin <gooksankoo@hoiptorrow.mailexpire.com>
Diffstat (limited to 'lib/Crypto/PublicKey/RSA.py')
-rw-r--r--lib/Crypto/PublicKey/RSA.py12
1 files changed, 7 insertions, 5 deletions
diff --git a/lib/Crypto/PublicKey/RSA.py b/lib/Crypto/PublicKey/RSA.py
index 363bb12..90df785 100644
--- a/lib/Crypto/PublicKey/RSA.py
+++ b/lib/Crypto/PublicKey/RSA.py
@@ -34,8 +34,7 @@ from Crypto.PublicKey import _RSA, _slowmath, pubkey
from Crypto import Random
from Crypto.Util.asn1 import DerObject, DerSequence
-from textwrap import fill
-import base64
+import binascii
try:
from Crypto.PublicKey import _fastmath
@@ -157,8 +156,11 @@ class _RSAobj(pubkey.pubkey):
return der.encode()
if format=='PEM':
pem = "-----BEGIN %s KEY-----\n" % keyType
- pem += fill(base64.b64encode(der.encode()),64)
- pem += "\n-----END %s KEY-----" % keyType
+ binaryKey = der.encode()
+ # Each BASE64 line can take up to 64 characters (=48 bytes of data)
+ chunks = [ binascii.b2a_base64(binaryKey[i:i+48]) for i in range(0, len(binaryKey), 48) ]
+ pem += ''.join(chunks)
+ pem += "-----END %s KEY-----" % keyType
return pem
return ValueError("")
@@ -238,7 +240,7 @@ class RSAImplementation(object):
if externKey.startswith('-----'):
# This is probably a PEM encoded key
lines = externKey.replace(" ",'').split()
- der = base64.b64decode(''.join(lines[1:-1]))
+ der = binascii.a2b_base64(''.join(lines[1:-1]))
return self._importKeyDER(der)
if externKey[0]=='\x30':
# This is probably a DER encoded key