Module PKCS1_v1_5
RSA encryption protocol according to PKCS#1 v1.5
See RFC3447 or the original RSA Labs specification .
This scheme is more properly called RSAES-PKCS1-v1_5.
If you are designing a new protocol, consider using the more robust PKCS#1 OAEP.
As an example, a sender may encrypt a message in this way:
>>> from Cryptodome.Cipher import PKCS1_v1_5
>>> from Cryptodome.PublicKey import RSA
>>> from Cryptodome.Hash import SHA
>>>
>>> message = b'To be encrypted'
>>> h = SHA.new(message)
>>>
>>> key = RSA.importKey(open('pubkey.der').read())
>>> cipher = PKCS1_v1_5.new(key)
>>> ciphertext = cipher.encrypt(message+h.digest())
At the receiver side, decryption can be done using the private part of
the RSA key:
>>> From Cryptodome.Hash import SHA
>>> from Cryptodome import Random
>>>
>>> key = RSA.importKey(open('privkey.der').read())
>>>
>>> dsize = SHA.digest_size
>>> sentinel = Random.new().read(15+dsize)
>>>
>>> cipher = PKCS1_v1_5.new(key)
>>> message = cipher.decrypt(ciphertext, sentinel)
>>>
>>> digest = SHA.new(message[:-dsize]).digest()
>>> if digest==message[-dsize:]:
>>> print "Encryption was correct."
>>> else:
>>> print "Encryption was not correct."
|
PKCS115_Cipher
This cipher can perform PKCS#1 v1.5 RSA encryption or decryption.
|
|
new(key,
randfunc=None)
Return a cipher object PKCS115_Cipher that can be used to perform PKCS#1 v1.5 encryption or decryption. |
|
|
Return a cipher object PKCS115_Cipher that can be used to perform PKCS#1 v1.5 encryption or decryption.
- Parameters:
|