Package tlslite :: Package utils :: Module RSAKey :: Class RSAKey
[show private | hide private]
[frames | no frames]

Class RSAKey

Known Subclasses:
OpenSSL_RSAKey, PyCrypto_RSAKey, Python_RSAKey

This is an abstract base class for RSA keys.

Particular implementations of RSA keys, such as OpenSSL_RSAKey.OpenSSL_RSAKey, Python_RSAKey.Python_RSAKey, and PyCrypto_RSAKey.PyCrypto_RSAKey, inherit from this.

To create or parse an RSA key, don't use one of these classes directly. Instead, use the factory functions in tlslite.utils.keyfactory.
Method Summary
  __init__(self, n, e)
Create a new RSA key.
int __len__(self)
Return the length of this key in bits.
bool acceptsPassword(self)
Return True if the write() method accepts a password for use in encrypting the private key.
array.array of unsigned bytes or None. decrypt(self, encBytes)
Decrypt the passed-in bytes.
array.array of unsigned bytes. encrypt(self, bytes)
Encrypt the passed-in bytes.
tlslite.utils.RSAKey.RSAKey generate(bits)
Generate a new key with the specified bit length. (Static method)
str getSigningAlgorithm(self)
Return the cryptoID sigAlgo value corresponding to this key.
str hash(self)
Return the cryptoID <keyHash> value corresponding to this key.
array.array of unsigned bytes. hashAndSign(self, bytes)
Hash and sign the passed-in bytes.
bool hashAndVerify(self, sigBytes, bytes)
Hash and verify the passed-in bytes with the signature.
bool hasPrivateKey(self)
Return whether or not this key has a private component.
array.array of unsigned bytes. sign(self, bytes)
Sign the passed-in bytes.
bool verify(self, sigBytes, bytes)
Verify the passed-in bytes with the signature.
str write(self, password)
Return a string containing the key.
str writeXMLPublicKey(self, indent)
Return a string containing the key.

Instance Method Details

__init__(self, n=0, e=0)
(Constructor)

Create a new RSA key.

If n and e are passed in, the new key will be initialized.
Parameters:
n - RSA modulus.
           (type=int)
e - RSA public exponent.
           (type=int)

__len__(self)
(Length operator)

Return the length of this key in bits.
Returns:
int

acceptsPassword(self)

Return True if the write() method accepts a password for use in encrypting the private key.
Returns:
bool

decrypt(self, encBytes)

Decrypt the passed-in bytes.

This requires the key to have a private component. It performs PKCS1 decryption of the passed-in data.
Parameters:
encBytes - The value which will be decrypted.
           (type=array.array of unsigned bytes)
Returns:
A PKCS1 decryption of the passed-in data or None if the data is not properly formatted.
           (type=array.array of unsigned bytes or None.)

encrypt(self, bytes)

Encrypt the passed-in bytes.

This performs PKCS1 encryption of the passed-in data.
Parameters:
bytes - The value which will be encrypted.
           (type=array.array of unsigned bytes)
Returns:
A PKCS1 encryption of the passed-in data.
           (type=array.array of unsigned bytes.)

getSigningAlgorithm(self)

Return the cryptoID sigAlgo value corresponding to this key.
Returns:
str

hash(self)

Return the cryptoID <keyHash> value corresponding to this key.
Returns:
str

hashAndSign(self, bytes)

Hash and sign the passed-in bytes.

This requires the key to have a private component. It performs a PKCS1-SHA1 signature on the passed-in data.
Parameters:
bytes - The value which will be hashed and signed.
           (type=str or array.array of unsigned bytes)
Returns:
A PKCS1-SHA1 signature on the passed-in data.
           (type=array.array of unsigned bytes.)

hashAndVerify(self, sigBytes, bytes)

Hash and verify the passed-in bytes with the signature.

This verifies a PKCS1-SHA1 signature on the passed-in data.
Parameters:
sigBytes - A PKCS1-SHA1 signature.
           (type=array.array of unsigned bytes)
bytes - The value which will be hashed and verified.
           (type=str or array.array of unsigned bytes)
Returns:
Whether the signature matches the passed-in data.
           (type=bool)

hasPrivateKey(self)

Return whether or not this key has a private component.
Returns:
bool

sign(self, bytes)

Sign the passed-in bytes.

This requires the key to have a private component. It performs a PKCS1 signature on the passed-in data.
Parameters:
bytes - The value which will be signed.
           (type=array.array of unsigned bytes)
Returns:
A PKCS1 signature on the passed-in data.
           (type=array.array of unsigned bytes.)

verify(self, sigBytes, bytes)

Verify the passed-in bytes with the signature.

This verifies a PKCS1 signature on the passed-in data.
Parameters:
sigBytes - A PKCS1 signature.
           (type=array.array of unsigned bytes)
bytes - The value which will be verified.
           (type=array.array of unsigned bytes)
Returns:
Whether the signature matches the passed-in data.
           (type=bool)

write(self, password=None)

Return a string containing the key.
Returns:
A string describing the key, in whichever format (PEM or XML) is native to the implementation.
           (type=str)

writeXMLPublicKey(self, indent='')

Return a string containing the key.
Returns:
A string describing the public key, in XML format.
           (type=str)

Static Method Details

generate(bits)

Generate a new key with the specified bit length.
Returns:
tlslite.utils.RSAKey.RSAKey

Generated by Epydoc 2.0 on Mon Feb 21 21:56:55 2005 http://epydoc.sf.net