Package M2Crypto :: Module RSA :: Class RSA
[frames] | no frames]

Class RSA




RSA Key Pair.

Instance Methods
 
__del__(self)
 
__getattr__(self, name)
 
__init__(self, rsa, _pyfree=0)
 
__len__(self)
 
as_pem(self, cipher='aes_128_cbc', callback=<function passphrase_callback at 0x83b2a04>)
Returns the key(pair) as a string in PEM format.
 
check_key(self)
 
m2_rsa_free(...)
 
private_decrypt(self, data, padding)
 
private_encrypt(self, data, padding)
 
pub(self)
 
public_decrypt(self, data, padding)
 
public_encrypt(self, data, padding)
 
save_key(self, file, cipher='aes_128_cbc', callback=<function passphrase_callback at 0x83b2a04>)
Save the key pair to a file in PEM format.
 
save_key_bio(self, bio, cipher='aes_128_cbc', callback=<function passphrase_callback at 0x83b2a04>)
Save the key pair to an M2Crypto.BIO.BIO object in PEM format.
 
save_key_der(self, file)
Save the key pair to a file in DER format.
 
save_key_der_bio(self, bio)
Save the key pair to an M2Crypto.BIO.BIO object in DER format.
 
save_pem(self, file, cipher='aes_128_cbc', callback=<function passphrase_callback at 0x83b2a04>)
Save the key pair to a file in PEM format.
 
save_pub_key(self, file)
Save the public key to a file in PEM format.
 
save_pub_key_bio(self, bio)
Save the public key to an M2Crypto.BIO.BIO object in PEM format.
 
sign(self, digest, algo='sha1')
Signs a digest with the private key
 
sign_rsassa_pss(self, digest, algo='sha1', salt_length=20)
Signs a digest with the private key using RSASSA-PSS
 
verify(self, data, signature, algo='sha1')
Verifies the signature with the public key
 
verify_rsassa_pss(self, data, signature, algo='sha1', salt_length=20)
Verifies the signature RSASSA-PSS
Method Details

save_key(self, file, cipher='aes_128_cbc', callback=<function passphrase_callback at 0x83b2a04>)

 

Save the key pair to a file in PEM format.

Parameters:
  • file (string) - Name of file to save key to.
  • cipher (string) - Symmetric cipher to protect the key. The default cipher is 'aes_128_cbc'. If cipher is None, then the key is saved in the clear.
  • callback (Python callable) - A Python callable object that is invoked to acquire a passphrase with which to protect the key. The default is util.passphrase_callback.

save_key_bio(self, bio, cipher='aes_128_cbc', callback=<function passphrase_callback at 0x83b2a04>)

 

Save the key pair to an M2Crypto.BIO.BIO object in PEM format.

Parameters:
  • bio (M2Crypto.BIO.BIO) - M2Crypto.BIO.BIO object to save key to.
  • cipher (string) - Symmetric cipher to protect the key. The default cipher is 'aes_128_cbc'. If cipher is None, then the key is saved in the clear.
  • callback (Python callable) - A Python callable object that is invoked to acquire a passphrase with which to protect the key. The default is util.passphrase_callback.

save_key_der(self, file)

 

Save the key pair to a file in DER format.

Parameters:
  • file (str) - Filename to save key to

save_key_der_bio(self, bio)

 

Save the key pair to an M2Crypto.BIO.BIO object in DER format.

Parameters:
  • bio (M2Crypto.BIO.BIO) - M2Crypto.BIO.BIO object to save key to.

save_pem(self, file, cipher='aes_128_cbc', callback=<function passphrase_callback at 0x83b2a04>)

 

Save the key pair to a file in PEM format.

Parameters:
  • file (string) - Name of file to save key to.
  • cipher (string) - Symmetric cipher to protect the key. The default cipher is 'aes_128_cbc'. If cipher is None, then the key is saved in the clear.
  • callback (Python callable) - A Python callable object that is invoked to acquire a passphrase with which to protect the key. The default is util.passphrase_callback.

save_pub_key(self, file)

 

Save the public key to a file in PEM format.

Parameters:
  • file (string) - Name of file to save key to.

save_pub_key_bio(self, bio)

 

Save the public key to an M2Crypto.BIO.BIO object in PEM format.

Parameters:
  • bio (M2Crypto.BIO.BIO) - M2Crypto.BIO.BIO object to save key to.

sign(self, digest, algo='sha1')

 

Signs a digest with the private key

Parameters:
  • digest (str) - A digest created by using the digest method
  • algo (str) - The method that created the digest. Legal values are 'sha1','sha224', 'sha256', 'ripemd160', and 'md5'.
Returns:
a string which is the signature

sign_rsassa_pss(self, digest, algo='sha1', salt_length=20)

 

Signs a digest with the private key using RSASSA-PSS

Parameters:
  • digest (str) - A digest created by using the digest method
  • salt_length (int) - The length of the salt to use
  • algo (str) - The hash algorithm to use
Returns:
a string which is the signature

verify(self, data, signature, algo='sha1')

 

Verifies the signature with the public key

Parameters:
  • data (str) - Data that has been signed
  • signature (str) - The signature signed with the private key
  • algo (str) - The method use to create digest from the data before it was signed. Legal values are 'sha1','sha224', 'sha256', 'ripemd160', and 'md5'.
Returns:
True or False, depending on whether the signature was verified.

verify_rsassa_pss(self, data, signature, algo='sha1', salt_length=20)

 

Verifies the signature RSASSA-PSS

Parameters:
  • data (str) - Data that has been signed
  • signature (str) - The signature signed with RSASSA-PSS
  • salt_length (int) - The length of the salt that was used
  • algo (str) - The hash algorithm to use
Returns:
1 or 0, depending on whether the signature was verified or not.