tlslite.utils.rsakey.RSAKey

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

# Class RSAKey

source code

    object --+
             |
            RSAKey

Known Subclasses:
  - python_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.

Instance Methods | [hide private]
__init__(self, n=0, e=0) Create a new RSA key. | source code
int |
__len__(self) Return the length of this key in bits. | source code
_addPKCS1Padding(self, bytes, blockType) | source code
_addPKCS1SHA1Prefix(self, bytes, withNULL=True) | source code
_rawPrivateKeyOp(self, m) | source code
_rawPublicKeyOp(self, c) | source code
bool |
acceptsPassword(self) Return True if the write() method accepts a password for use in encrypting the private key. | source code
`bytearray` of unsigned bytes or None. |
decrypt(self, encBytes) Decrypt the passed-in bytes. | source code
`bytearray` of unsigned bytes. |
encrypt(self, bytes) Encrypt the passed-in bytes. | source code
bool |
hasPrivateKey(self) Return whether or not this key has a private component. | source code
`bytearray` of unsigned bytes. |
hashAndSign(self, bytes) Hash and sign the passed-in bytes. | source code
bool |
hashAndVerify(self, sigBytes, bytes) Hash and verify the passed-in bytes with the signature. | source code
`bytearray` of unsigned bytes. |
sign(self, bytes) Sign the passed-in bytes. | source code
bool |
verify(self, sigBytes, bytes) Verify the passed-in bytes with the signature. | source code
str |
write(self, password=None) Return a string containing the key. | source code
Inherited from `object`: `__delattr__`, `__format__`, `__getattribute__`, `__hash__`, `__new__`, `__reduce__`, `__reduce_ex__`, `__repr__`, `__setattr__`, `__sizeof__`, `__str__`, `__subclasshook__`

Static Methods | [hide private]
tlslite.utils.RSAKey.RSAKey |
generate(bits) Generate a new key with the specified bit length. | source code

Properties | [hide private]
Inherited from `object`: `__class__`

Method Details | [hide private]

### __init__(self, n=0, e=0) (Constructor) | source code
Create a new RSA key. If n and e are passed in, the new key will be initialized. Parameters: `n` (int) - RSA modulus. `e` (int) - RSA public exponent. Overrides: object.__init__

### decrypt(self, encBytes) | source code
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` (`bytearray` of unsigned bytes) - The value which will be decrypted. Returns: `bytearray` of unsigned bytes or None. A PKCS1 decryption of the passed-in data or None if the data is not properly formatted.

### encrypt(self, bytes) | source code
Encrypt the passed-in bytes. This performs PKCS1 encryption of the passed-in data. Parameters: `bytes` (`bytearray` of unsigned bytes) - The value which will be encrypted. Returns: `bytearray` of unsigned bytes. A PKCS1 encryption of the passed-in data.

### hashAndSign(self, bytes) | source code
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` (str or `bytearray` of unsigned bytes) - The value which will be hashed and signed. Returns: `bytearray` of unsigned bytes. A PKCS1-SHA1 signature on the passed-in data.

### hashAndVerify(self, sigBytes, bytes) | source code
Hash and verify the passed-in bytes with the signature. This verifies a PKCS1-SHA1 signature on the passed-in data. Parameters: `sigBytes` (`bytearray` of unsigned bytes) - A PKCS1-SHA1 signature. `bytes` (str or `bytearray` of unsigned bytes) - The value which will be hashed and verified. Returns: bool Whether the signature matches the passed-in data.

### sign(self, bytes) | source code
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` (`bytearray` of unsigned bytes) - The value which will be signed. Returns: `bytearray` of unsigned bytes. A PKCS1 signature on the passed-in data.

### verify(self, sigBytes, bytes) | source code
Verify the passed-in bytes with the signature. This verifies a PKCS1 signature on the passed-in data. Parameters: `sigBytes` (`bytearray` of unsigned bytes) - A PKCS1 signature. `bytes` (`bytearray` of unsigned bytes) - The value which will be verified. Returns: bool Whether the signature matches the passed-in data.

### write(self, password=None) | source code
Return a string containing the key. Returns: str A string describing the key, in whichever format (PEM) is native to the implementation.