python 2.7 - RSA Signature is different generated from rsa module and m2crypto -


i migrating service python 2.7 python 3.5 communicated service using rsa encryption/decryption.


python(v2.7) m2crypto(0.25.1) < correct signature >

key = m2crypto.rsa.load_key(private_key) digest = hashlib.sha1(bytes(cipher_text, encoding="utf-8")).hexdigest() signature = hexlify(key.private_encrypt(digest, m2crypto.rsa.pkcs1_padding)) 

python(v3.5) rsa(v3.4.2)

pri_key = rsa.privatekey.load_pkcs1(private_key) signature = hexlify(rsa.sign(cipher_text.encode(), pri_key, "sha-1")) 

signature produced above codes different. difference between these packages?

you executing different cryptographic operations. encrypt private key != digital signature

signature = hexlify(key.private_encrypt(digest, m2crypto.rsa.pkcs1_padding)) 

and

signature = hexlify(rsa.sign(cipher_text.encode(), pri_key, "sha-1")) 

a digital signature pcks#1 v1.5 makes rsa encryption on digest algorithm identifier , digest of message encoded in asn.1

signature =      rsa_encryption(        asn.1(digestalgorithmidentifier  + sha1(message) ))  

while encryption not include digest algorithm identifier

seems python key.private_encrypt wrapper on openssl rsa_private_encrypt take warning thepkcs1_padding using

rsa_pkcs1_padding

pkcs #1 v1.5 padding. function not handle algorithmidentifier specified in pkcs #1. when generating or verifying pkcs #1 signatures, rsa_sign(3) , rsa_verify(3) should used.

you should use sign , not private_encrypt digital signatures. if want encryption hide content of message, should use encryption public key, not private.


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -