tlslite.utils.keyfactory

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

## Module tlslite.utils.keyfactory

Factory functions for asymmetric cryptography.

Function Summary
`tlslite.utils.RSAKey.RSAKey` | ``generateRSAKey`(bits, implementations)` Generate an RSA key with the specified bit length.
`tlslite.utils.RSAKey.RSAKey` | ``parseXMLKey`(s, private, public, implementations)` Parse an XML-format key.
`tlslite.utils.RSAKey.RSAKey` | ``parsePEMKey`(s, private, public, passwordCallback, implementations)` Parse a PEM-format key.
`tlslite.utils.RSAKey.RSAKey` | ``parseAsPublicKey`(s)` Parse an XML or PEM-formatted public key.
`tlslite.utils.RSAKey.RSAKey` | ``parsePrivateKey`(s)` Parse an XML or PEM-formatted private key.

Function Details

### generateRSAKey(bits, implementations=['openssl', 'python']) Generate an RSA key with the specified bit length. Parameters: `bits` - Desired bit length of the new key's modulus. (type=int) Returns: A new RSA private key. (type=`tlslite.utils.RSAKey.RSAKey`)

### parseXMLKey(s, private=False, public=False, implementations=['python']) Parse an XML-format key. The XML format used here is specific to tlslite and cryptoIDlib. The format can store the public component of a key, or the public and private components. For example:
       <publicKey xmlns="http://trevp.net/rsa">
           <n>4a5yzB8oGNlHo866CAspAC47M4Fvx58zwK8pou...
           <e>Aw==</e>
       </publicKey>

       <privateKey xmlns="http://trevp.net/rsa">
           <n>4a5yzB8oGNlHo866CAspAC47M4Fvx58zwK8pou...
           <e>Aw==</e>
           <d>JZ0TIgUxWXmL8KJ0VqyG1V0J3ern9pqIoB0xmy...
           <p>5PreIj6z6ldIGL1V4+1C36dQFHNCQHJvW52GXc...
           <q>/E/wDit8YXPCxx126zTq2ilQ3IcW54NJYyNjiZ...
           <dP>mKc+wX8inDowEH45Qp4slRo1YveBgExKPROu6...
           <dQ>qDVKtBz9lk0shL5PR3ickXDgkwS576zbl2ztB...
           <qInv>j6E8EA7dNsTImaXexAmLA1DoeArsYeFAInr...
       </privateKey>
Parameters: `s` - A string containing an XML public or private key. (type=str) `private` - If True, a `SyntaxError` will be raised if the private key component is not present. (type=bool) `public` - If True, the private key component (if present) will be discarded, so this function will always return a public key. (type=bool) Returns: An RSA key. (type=`tlslite.utils.RSAKey.RSAKey`) Raises: `SyntaxError` - If the key is not properly formatted.

### parsePEMKey(s, private=False, public=False, passwordCallback=None, implementations=['openssl', 'python']) Parse a PEM-format key. The PEM format is used by OpenSSL and other tools. The format is typically used to store both the public and private components of a key. For example:
      -----BEGIN RSA PRIVATE KEY-----
       MIICXQIBAAKBgQDYscuoMzsGmW0pAYsmyHltxB2TdwHS0dImfjCMfaSDkfLdZY5+
       dOWORVns9etWnr194mSGA1F0Pls/VJW8+cX9+3vtJV8zSdANPYUoQf0TP7VlJxkH
       dSRkUbEoz5bAAs/+970uos7n7iXQIni+3erUTdYEk2iWnMBjTljfgbK/dQIDAQAB
       AoGAJHoJZk75aKr7DSQNYIHuruOMdv5ZeDuJvKERWxTrVJqE32/xBKh42/IgqRrc
       esBN9ZregRCd7YtxoL+EVUNWaJNVx2mNmezEznrc9zhcYUrgeaVdFO2yBF1889zO
       gCOVwrO8uDgeyj6IKa25H6c1N13ih/o7ZzEgWbGG+ylU1yECQQDv4ZSJ4EjSh/Fl
       aHdz3wbBa/HKGTjC8iRy476Cyg2Fm8MZUe9Yy3udOrb5ZnS2MTpIXt5AF3h2TfYV
       VoFXIorjAkEA50FcJmzT8sNMrPaV8vn+9W2Lu4U7C+K/O2g1iXMaZms5PC5zV5aV
       CKXZWUX1fq2RaOzlbQrpgiolhXpeh8FjxwJBAOFHzSQfSsTNfttp3KUpU0LbiVvv
       i+spVSnA0O4rq79KpVNmK44Mq67hsW1P11QzrzTAQ6GVaUBRv0YS061td1kCQHnP
       wtN2tboFR6lABkJDjxoGRvlSt4SOPr7zKGgrWjeiuTZLHXSAnCY+/hr5L9Q3ZwXG
       6x6iBdgLjVIe4BZQNtcCQQDXGv/gWinCNTN3MPWfTW/RGzuMYVmyBFais0/VrgdH
       h1dLpztmpQqfyH/zrBXQ9qL/zR4ojS6XYneO/U18WpEe
       -----END RSA PRIVATE KEY-----
To generate a key like this with OpenSSL, run:
       openssl genrsa 2048 > key.pem
This format also supports password-encrypted private keys. TLS Lite can only handle password-encrypted private keys when OpenSSL and M2Crypto are installed. In this case, passwordCallback will be invoked to query the user for the password. Parameters: `s` - A string containing a PEM-encoded public or private key. (type=str) `private` - If True, a `SyntaxError` will be raised if the private key component is not present. (type=bool) `public` - If True, the private key component (if present) will be discarded, so this function will always return a public key. (type=bool) `passwordCallback` - This function will be called, with no arguments, if the PEM-encoded private key is password-encrypted. The callback should return the password string. If the password is incorrect, SyntaxError will be raised. If no callback is passed and the key is password-encrypted, a prompt will be displayed at the console. (type=callable) Returns: An RSA key. (type=`tlslite.utils.RSAKey.RSAKey`) Raises: `SyntaxError` - If the key is not properly formatted.

### parseAsPublicKey(s) Parse an XML or PEM-formatted public key. Parameters: `s` - A string containing an XML or PEM-encoded public or private key. (type=str) Returns: An RSA public key. (type=`tlslite.utils.RSAKey.RSAKey`) Raises: `SyntaxError` - If the key is not properly formatted.

### parsePrivateKey(s) Parse an XML or PEM-formatted private key. Parameters: `s` - A string containing an XML or PEM-encoded private key. (type=str) Returns: An RSA private key. (type=`tlslite.utils.RSAKey.RSAKey`) Raises: `SyntaxError` - If the key is not properly formatted.

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