Package Crypto :: Package Cipher :: Module PKCS1_OAEP :: Class PKCS1OAEP_Cipher
[frames] | no frames]

Class PKCS1OAEP_Cipher

This cipher can perform PKCS#1 v1.5 OAEP encryption or decryption.
Instance Methods
 
__init__(self, key, hashAlgo, mgfunc, label)
Initialize this PKCS#1 OAEP cipher object.
 
can_encrypt(self)
Return True/1 if this cipher object can be used for encryption.
 
can_decrypt(self)
Return True/1 if this cipher object can be used for decryption.
 
encrypt(self, message)
Produce the PKCS#1 OAEP encryption of a message.
 
decrypt(self, ct)
Decrypt a PKCS#1 OAEP ciphertext.
Method Details

__init__(self, key, hashAlgo, mgfunc, label)
(Constructor)

 
Initialize this PKCS#1 OAEP cipher object.
Parameters:
  • key (an RSA key object) - If a private half is given, both encryption and decryption are possible. If a public half is given, only encryption is possible.
  • hashAlgo (hash object) - The hash function to use. This can be a module under Crypto.Hash or an existing hash object created from any of such modules. If not specified, Crypto.Hash.SHA (that is, SHA-1) is used.
  • mgfunc (callable) - A mask generation function that accepts two parameters: a string to use as seed, and the lenth of the mask to generate, in bytes. If not specified, the standard MGF1 is used (a safe choice).
  • label (string) - A label to apply to this particular encryption. If not specified, an empty string is used. Specifying a label does not improve security.

Attention: Modify the mask generation function only if you know what you are doing. Sender and receiver must use the same one.

encrypt(self, message)

 

Produce the PKCS#1 OAEP encryption of a message.

This function is named RSAES-OAEP-ENCRYPT, and is specified in section 7.1.1 of RFC3447.

Parameters:
  • message (string) - The message to encrypt, also known as plaintext. It can be of variable length, but not longer than the RSA modulus (in bytes) minus 2, minus twice the hash output size.
Returns:
A string, the ciphertext in which the message is encrypted. It is as long as the RSA modulus (in bytes).
Raises:
  • ValueError - If the RSA key length is not sufficiently long to deal with the given message.

decrypt(self, ct)

 

Decrypt a PKCS#1 OAEP ciphertext.

This function is named RSAES-OAEP-DECRYPT, and is specified in section 7.1.2 of RFC3447.

Parameters:
  • ct (string) - The ciphertext that contains the message to recover.
Returns:
A string, the original message.
Raises:
  • ValueError - If the ciphertext length is incorrect, or if the decryption does not succeed.
  • TypeError - If the RSA key has no private half.