Package paramiko :: Module pkey :: Class PKey
[frames] | no frames]

Class PKey

source code

object --+
         |
        PKey
Known Subclasses:

Base class for public keys.

Instance Methods
 
__cmp__(self, other)
Compare this key to another.
source code
 
__eq__(self, other) source code
 
__init__(self, msg=None, data=None)
Create a new instance of this public key type.
source code
 
__str__(self)
str(x)
source code
 
asbytes(self)
Return a string of an SSH `.Message` made up of the public part(s) of this key.
source code
 
can_sign(self)
Return ``True`` if this key has the private part necessary for signing data.
source code
 
get_base64(self)
Return a base64 string containing the public part of this key.
source code
 
get_bits(self)
Return the number of significant bits in this key.
source code
 
get_fingerprint(self)
Return an MD5 fingerprint of the public part of this key.
source code
 
get_name(self)
Return the name of this private key implementation.
source code
 
sign_ssh_data(self, data)
Sign a blob of data with this private key, and return a `.Message` representing an SSH signature message.
source code
 
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.
source code
 
write_private_key(self, file_obj, password=None)
Write private key contents into a file (or file-like) object.
source code
 
write_private_key_file(self, filename, password=None)
Write private key contents into a file.
source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __subclasshook__

Class Methods
 
from_private_key(cls, file_obj, password=None)
Create a key object by reading a private key from a file (or file-like) object.
source code
 
from_private_key_file(cls, filename, password=None)
Create a key object by reading a private key file.
source code
Properties

Inherited from object: __class__

Method Details

__cmp__(self, other)
(Comparison operator)

source code 

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.

:param .Pkey other: key to compare to.

__init__(self, msg=None, data=None)
(Constructor)

source code 

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.

:param .Message msg:
    an optional SSH `.Message` containing a public key of this type.
:param str data: an optional string containing a public key of this type

:raises SSHException:
    if a key cannot be created from the ``data`` or ``msg`` given, or
    no key was passed in.

Overrides: object.__init__

__str__(self)
(Informal representation operator)

source code 

str(x)

Overrides: object.__str__
(inherited documentation)

asbytes(self)

source code 

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.

from_private_key(cls, file_obj, password=None)
Class Method

source code 

Create a key object by reading a private key from a file (or file-like)
object.  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).

:param file file_obj: the file to read from
:param str password:
    an optional password to use to decrypt the key, if it's encrypted
:return: a new `.PKey` based on the given private key

:raises IOError: if there was an error reading the key
:raises PasswordRequiredException: if the private key file is encrypted,
    and ``password`` is ``None``
:raises SSHException: if the key file is invalid

from_private_key_file(cls, filename, password=None)
Class Method

source code 

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.

:param str filename: name of the file to read
:param str password: an optional password to use to decrypt the key file,
    if it's encrypted
:return: a new `.PKey` based on the given private key

:raises IOError: if there was an error reading the file
:raises PasswordRequiredException: if the private key file is
    encrypted, and ``password`` is ``None``
:raises SSHException: if the key file is invalid

get_base64(self)

source code 

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.

:return: a base64 `string <str>` containing the public part of the key.

get_bits(self)

source code 

Return the number of significant bits in this key. This is useful for judging the relative security of a key.

:return: bits in the key (as an `int`)

get_fingerprint(self)

source code 

Return an MD5 fingerprint of the public part of this key.  Nothing
secret is revealed.

:return:
    a 16-byte `string <str>` (binary) of the MD5 fingerprint, in SSH
    format.

get_name(self)

source code 

Return the name of this private key implementation.

:return:
    name of this private key type, in SSH terminology, as a `str` (for
    example, ``"ssh-rsa"``).

sign_ssh_data(self, data)

source code 

Sign a blob of data with this private key, and return a `.Message` representing an SSH signature message.

:param str data: the data to sign. :return: an SSH signature `message <.Message>`.

verify_ssh_sig(self, data, msg)

source code 

Given a blob of data, and an SSH message representing a signature of
that data, verify that it was signed with this key.

:param str data: the data that was signed.
:param .Message msg: an SSH signature message
:return:
    ``True`` if the signature verifies correctly; ``False`` otherwise.

write_private_key(self, file_obj, password=None)

source code 

Write private key contents into a file (or file-like) object. If the password is not ``None``, the key is encrypted before writing.

:param file file_obj: the file object to write into :param str password: an optional password to use to encrypt the key

:raises IOError: if there was an error writing to the file :raises SSHException: if the key is invalid

write_private_key_file(self, filename, password=None)

source code 

Write private key contents into a file.  If the password is not
``None``, the key is encrypted before writing.

:param str filename: name of the file to write
:param str password:
    an optional password to use to encrypt the key file

:raises IOError: if there was an error writing the file
:raises SSHException: if the key is invalid