m2crypto encryption with private key

This is the place for queries that don't fit in any of the other categories.

m2crypto encryption with private key

Postby johnyjj2 » Fri Jun 13, 2014 6:18 pm

Hello,

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 (http://sheogora.blogspot.com/2012/03/m2crypto-for-python-x509-certificates.html says "to encrypt a message using the public key above" and here https://gist.github.com/Snegovikufa/5232301 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 (http://www.heikkitoivonen.net/m2crypto/api/M2Crypto.RSA-module.html).

Thanks for help in advance :-)
Last edited by Yoriz on Fri Jun 13, 2014 7:22 pm, edited 1 time in total.
Reason: First post lock.
johnyjj2
 
Posts: 2
Joined: Fri Jun 13, 2014 6:05 pm

Re: m2crypto encryption with private key

Postby johnyjj2 » Thu Jun 19, 2014 8:11 am

Hello,
could you give me some guidelines on this topic?
Thanks in advance :-)!
johnyjj2
 
Posts: 2
Joined: Fri Jun 13, 2014 6:05 pm


Return to General Coding Help

Who is online

Users browsing this forum: No registered users and 2 guests