I am new to Python world and I need some advice on encryption with m2crypto. I have created code that can calculate hash from some text data.
- Code: Select all
from M2Crypto import *
import hashlib
def new(request):
# ...
if request.POST:
# ...
myHash = hashlib.sha1(documentContent).hexdigest()
print myHash
Now I want to do two additional things, i.e. read private key from the file and use that private key to sign the hash / generate certificate. How can I achieve that?
I have found that reading the file may be done in this way:
- Code: Select all
import M2Crypto
pk = M2Crypto.RSA.load_key('private.pem')
But I was unable to find any way to sign it with private key. All the threads I have found were about signing something with public key ( says "to encrypt a message using the public key above" and here with "encrypt the message using that public key"). And after all, should I use M2Crypto.RSA or M2Crypto.X509?
In m2crypto.rsa I could not find any 'encrypt' method ().
Thanks for help in advance
