DER Derivation of RSA Key Using M2Crypto

The M2Crypto.RSA.RSA().save_key_der() method can be used to save the key in DER format. However, I do not see the corresponding M2Crypto.RSA.load_key_der() method, as expected.

Is there a way to download a DAR-encoded RSA key using M2Crypto?

+3
source share
1 answer

The PEM format is base64 encoded DER data with some additional header and footer lines. You can just read DER as binary, convert it to PEM, and pass it to RSA.load_key_string :

 import base64 from M2Crypto import RSA TEMPLATE = """ -----BEGIN RSA PRIVATE KEY----- %s -----END RSA PRIVATE KEY----- """ raw = open('key.der', 'rb').read() data = TEMPLATE % base64.encodestring(raw).rstrip() key = RSA.load_key_string(data) print key 

Conclusion:

 <M2Crypto.RSA.RSA instance at 0x10eb710> 
+10
source

Source: https://habr.com/ru/post/913287/


All Articles