paramiko.PKey

Package paramiko :: Class PKey |
[show private | hide private]
[frames | no frames]

## Type PKey

    object --+
             |
            PKey

Known Subclasses:
  `AgentKey`, `DSSKey`, `RSAKey`

Base class for public keys.

Method Summary
| ``__init__`(self, msg, data)` Create a new instance of this public key type.
int | ``__cmp__`(self, other)` Compare this key to another.
str | ``__str__`(self)` Return a string of an SSH `Message` made up of the public part(s) of this key.
str | ``_read_private_key_file`(self, tag, filename, password)` Read an SSH2-format private key file, looking for a string of the type `"BEGIN xxx PRIVATE KEY"` for some `xxx`, base64-decode the text we find, and return it as a string.
| ``_write_private_key_file`(self, tag, filename, data, password)` Write an SSH2-format private key file in a form that can be read by paramiko or openssh.
bool | ``can_sign`(self)` Return `True` if this key has the private part necessary for signing data.
`PKey` | ``from_private_key_file`(cl, filename, password)` Create a key object by reading a private key file. (Class method)
str | ``get_base64`(self)` Return a base64 string containing the public part of this key.
int | ``get_bits`(self)` Return the number of significant bits in this key.
str | ``get_fingerprint`(self)` Return an MD5 fingerprint of the public part of this key.
str | ``get_name`(self)` Return the name of this private key implementation.
`Message` | ``sign_ssh_data`(self, randpool, data)` Sign a blob of data with this private key, and return a `Message` representing an SSH signature message.
boolean | ``verify_ssh_sig`(self, data, msg)` Given a blob of data, and an SSH message representing a signature of that data, verify that it was signed with this key.
| ``write_private_key_file`(self, filename, password)` Write private key contents into a file.
Inherited from object
| ``__delattr__`(...)` x.__delattr__('name') <==> del x.name
| ``__getattribute__`(...)` x.__getattribute__('name') <==> x.name
| ``__hash__`(x)` x.__hash__() <==> hash(x)
| ``__new__`(T, S, ...)` T.__new__(S, ...) -> a new object with type S, a subtype of T
| ``__reduce__`(...)` helper for pickle
| ``__reduce_ex__`(...)` helper for pickle
| ``__repr__`(x)` x.__repr__() <==> repr(x)
| ``__setattr__`(...)` x.__setattr__('name', value) <==> x.name = value

Class Variable Summary
`dict` | `_CIPHER_TABLE` = `{'DES-EDE3-CBC': {'blocksize': 8, 'ciphe...`

Instance Method Details

### __init__(self, msg=None, data=None) (Constructor) Create a new instance of this public key type. If `msg` is given, the key's public part(s) will be filled in from the message. If `data` is given, the key's public part(s) will be filled in from the string. Parameters: `msg` - an optional SSH `Message` containing a public key of this type. (type=`Message`) `data` - an optional string containing a public key of this type (type=str) Raises: `SSHException` - if a key cannot be created from the `data` or `msg` given, or no key was passed in. Overrides: `__builtin__.object.__init__`

### __cmp__(self, other) (Comparison operator) Compare this key to another. Returns 0 if this key is equivalent to the given key, or non-0 if they are different. Only the public parts of the key are compared, so a public key will compare equal to its corresponding private key. Parameters: `other` - key to compare to. (type=`PKey`) Returns: 0 if the two keys are equivalent, non-0 otherwise. (type=int)

### __str__(self) (Informal representation operator) Return a string of an SSH `Message` made up of the public part(s) of this key. This string is suitable for passing to `__init__` to re-create the key object later. Returns: string representation of an SSH key message. (type=str) Overrides: `__builtin__.object.__str__`

### _read_private_key_file(self, tag, filename, password=None) Read an SSH2-format private key file, looking for a string of the type `"BEGIN xxx PRIVATE KEY"` for some `xxx`, base64-decode the text we find, and return it as a string. If the private key is encrypted and `password` is not `None`, the given password will be used to decrypt the key (otherwise `PasswordRequiredException` is thrown). Parameters: `tag` - `"RSA"` or `"DSA"`, the tag used to mark the data block. (type=str) `filename` - name of the file to read. (type=str) `password` - an optional password to use to decrypt the key file, if it's encrypted. (type=str) Returns: data blob that makes up the private key. (type=str) Raises: `IOError` - if there was an error reading the file. `PasswordRequiredException` - if the private key file is encrypted, and `password` is `None`. `SSHException` - if the key file is invalid.

### _write_private_key_file(self, tag, filename, data, password=None) Write an SSH2-format private key file in a form that can be read by paramiko or openssh. If no password is given, the key is written in a trivially-encoded format (base64) which is completely insecure. If a password is given, DES-EDE3-CBC is used. Parameters: `tag` - `"RSA"` or `"DSA"`, the tag used to mark the data block. (type=str) `filename` - name of the file to write. (type=str) `data` - data blob that makes up the private key. (type=str) `password` - an optional password to use to encrypt the file. (type=str) Raises: `IOError` - if there was an error writing the file.

### can_sign(self) Return `True` if this key has the private part necessary for signing data. Returns: `True` if this is a private key. (type=bool)

### get_base64(self) Return a base64 string containing the public part of this key. Nothing secret is revealed. This format is compatible with that used to store public key files or recognized host keys. Returns: a base64 string containing the public part of the key. (type=str) Since: fearow

### get_bits(self) Return the number of significant bits in this key. This is useful for judging the relative security of a key. Returns: bits in the key. (type=int)

### get_fingerprint(self) Return an MD5 fingerprint of the public part of this key. Nothing secret is revealed. Returns: a 16-byte string (binary) of the MD5 fingerprint, in SSH format. (type=str)

### get_name(self) Return the name of this private key implementation. Returns: name of this private key type, in SSH terminology (for example, `"ssh-rsa"`). (type=str)

### sign_ssh_data(self, randpool, data) Sign a blob of data with this private key, and return a `Message` representing an SSH signature message. Parameters: `randpool` - a secure random number generator. (type=`Crypto.Util.randpool.RandomPool`) `data` - the data to sign. (type=str) Returns: an SSH signature message. (type=`Message`)

### verify_ssh_sig(self, data, msg) Given a blob of data, and an SSH message representing a signature of that data, verify that it was signed with this key. Parameters: `data` - the data that was signed. (type=str) `msg` - an SSH signature message (type=`Message`) Returns: `True` if the signature verifies correctly; `False` otherwise. (type=boolean)

### write_private_key_file(self, filename, password=None) Write private key contents into a file. If the password is not `None`, the key is encrypted before writing. Parameters: `filename` - name of the file to write. (type=str) `password` - an optional password to use to encrypt the key file. (type=str) Raises: `IOError` - if there was an error writing the file. `SSHException` - if the key is invalid. Since: fearow

Class Method Details

### from_private_key_file(cl, filename, password=None) Create a key object by reading a private key file. If the private key is encrypted and `password` is not `None`, the given password will be used to decrypt the key (otherwise `PasswordRequiredException` is thrown). Through the magic of python, this factory method will exist in all subclasses of PKey (such as `RSAKey` or `DSSKey`), but is useless on the abstract PKey class. Parameters: `filename` - name of the file to read. (type=str) `password` - an optional password to use to decrypt the key file, if it's encrypted (type=str) Returns: a new key object based on the given private key. (type=`PKey`) Raises: `IOError` - if there was an error reading the file. `PasswordRequiredException` - if the private key file is encrypted, and `password` is `None`. `SSHException` - if the key file is invalid. Since: fearow

Class Variable Details

    ### _CIPHER_TABLE Type: `dict` Value:
        {'DES-EDE3-CBC': {'blocksize': 8,
                          'cipher': <module 'Crypto.Cipher.DES3' from '/usr/li\
        b/python2.4/site-packages/Crypto/Cipher/DES3.so'>,
                          'keysize': 24,
                          'mode': 2}}

Generated by Epydoc 2.1 on Sun Dec 4 11:16:47 2005 | http://epydoc.sf.net