Package yawPyCrypto :: Module Key :: Class Key
[show private | hide private]
[frames | no frames]

Class Key

     object --+    
              |    
       IFlatten --+
                  |
     object --+   |
              |   |
AlgoDefinitions --+
                  |
                 Key

Known Subclasses:
SecureKey, SecureAsciiKey, AsciiKey

This class is the main entrypoint for working with public key algorithms from yawPyCrypto. It allows you to create keys, store them to string form, load them from strings (previously stored by calling one of the store*() functions), and also do standard operations on them such as en/decrypt data and sign/verify data. The Key class extends PyCrypto keys by providing them with a key attribute system. Key attributes may be private; this is checked by using the _isPrivate() method of this class. Keys stored/loaded by using this class are not protected, use the SecureKey from the AdvKey.py in case you need this.
Method Summary
  __init__(self, keysize, algo_pub, **kwargs)
Create a new key.
  __cmp__(self, other)
Compares two keys.
  __delitem__(self, name)
Deletes the specified key argument from this key.
  __getitem__(self, name)
Loads the key attribute name from the current key object, and unserializes it.
  __hash__(self)
Returns a hash value of a key instance.
  __iter__(self)
Return an iterator over all names of key arguments.
a new object with type S, a subtype of T __new__(S, ...)
  __setitem__(self, name, value)
Sets the passed in keyword argument called name to the value that is passed in along.
  canDecrypt(self)
Returns a boolean whether this key can decrypt data.
  canEncrypt(self)
Returns a boolean whether this key can encrypt data.
  canSign(self)
Returns a boolean whether this key can sign data.
  canVerify(self)
Returns a boolean whether this key can verify signed data.
  cryptSize(self)
Returns the maximum string length of data which can be encrypted or signed.
  decrypt(self, encdata, wrap, *args, **kwargs)
Decrypt string data as passed in using data.
  encrypt(self, data, wrap, *args, **kwargs)
Encrypt string data as passed in using data.
  hasPrivate(self)
Checks whether this key has a private key part.
  hasPublic(self)
Checks whether this key has a public key part.
  keySize(self)
Returns the key's keysize in bits.
  publicKey(self)
Returns a new key object which contains only the public key associated with the current key, and only public key arguments.
  sign(self, data, hash_algo, wrap, *args, **kwargs)
Create a new signature for the data that is passed in.
  storeKey(self, wrap, *args, **kwargs)
Stores a key to a string of bytes.
  storePublicKey(self, wrap, *args, **kwargs)
Stores only the public key of this key to a string of bytes.
  update(self, args)
Dictionary style updating for a Key instance.
  verify(self, data, signature, wrap, *args, **kwargs)
Verify the signature of the passed in string.

Class Variable Summary
property id
classmethod loadKey

Method Details

__init__(self, keysize=1024, algo_pub=3, **kwargs)
(Constructor)

Create a new key. The arguments passed to this function have the
following meaning:
    
    keysize - Integer specifying the size in bits of the key to
              create.
    algo_pub - One of the PUBLICKEY_* constants, specifies the
               public key algorithm to use.
    **kwargs - All extra keyword arguments are used to set key
               attributes.
               
All values have safe defaults; in case you instantiate this class
without specifying any parameters, an RSA key of length 1024 bits
is created, with no key arguments set.

__cmp__(self, other)
(Comparison operator)

Compares two keys. Two keys are equal if and only if their IDs match. This means that two keys can compare equal, although their key arguments are not equal.

__delitem__(self, name)
(Index deletion operator)

Deletes the specified key argument from this key. In case it is not present, a KeyError is raised.

__getitem__(self, name)
(Indexing operator)

Loads the key attribute name from the current key object, and unserializes it. Loading a key attribute checks for validity of the data by comparing the stored string representation against a signature which was stored on setting the attribute (in case the key contained a private key). In case no signature is found, the object is (by default) returned in an Untrusted() wrapping object. In case the signature found is bad, an exception is raised. This behaviour is configurable through the Config.py option WARN_ABOUT_UNTRUSTED_KEY_ARGUMENTS.

__hash__(self)
(Hashing function)

Returns a hash value of a key instance. The hash value is computed by computing the Python hash of the key's ID.

__iter__(self)

Return an iterator over all names of key arguments.

__new__(S, ...)

Returns:
a new object with type S, a subtype of T

__setitem__(self, name, value)
(Index assignment operator)

Sets the passed in keyword argument called name to the value that is passed in along. The value is stored using the serialize function from the Flatten module, and in case the current key has the possibility to sign values, a signature is stored along with the key-data.

canDecrypt(self)

Returns a boolean whether this key can decrypt data.

canEncrypt(self)

Returns a boolean whether this key can encrypt data.

canSign(self)

Returns a boolean whether this key can sign data.

canVerify(self)

Returns a boolean whether this key can verify signed data.

cryptSize(self)

Returns the maximum string length of data which can be encrypted or signed. This is equivalent to doing keySize() // 8.

decrypt(self, encdata, wrap=True, *args, **kwargs)

Decrypt string data as passed in using data. The string must have
been created by the encrypt() method of this class for decryption
to succeed. The parameters passed in have the following meaning:

    data - String data to be decrypted.
    wrap - Defaults to True. In case you use a Key derived class
           such as AsciiKey, specifies whether the decrypted data
           should be unwrapped before decrypting it.
    *args, **kwargs - All extra arguments are passed to the
                      unwrapping functions declared by the current
                      Key(-derived) class.

encrypt(self, data, wrap=True, *args, **kwargs)

Encrypt string data as passed in using data. The string data may
not be longer than self.cryptSize() for encryption to succeed. The
parameters passed in have the following meaning:

    data - String data to be encrypted.
    wrap - Defaults to True. In case you use a Key derived class
           such as AsciiKey, specifies whether the encrypted data
           should be wrapped after storing it.
    *args, **kwargs - All extra arguments are passed to the
                      wrapping functions declared by the current
                      Key(-derived) class.

hasPrivate(self)

Checks whether this key has a private key part.

hasPublic(self)

Checks whether this key has a public key part. Always returns true at the moment.

keySize(self)

Returns the key's keysize in bits.

publicKey(self)

Returns a new key object which contains only the public key associated with the current key, and only public key arguments. This is done by serializing the class, and then loading it again, so the two copies are disjoint.

sign(self, data, hash_algo=5, wrap=True, *args, **kwargs)

Create a new signature for the data that is passed in. The
signature is a string, which is returned. The parameters passed
in have the following meaning:

    data - String data to be signed.
    hash_algo - Hash algorithm to use to hash the data before
                signing it. Special value HASH_NONE for hash_algo
                means that no hashing of the data is done before
                signing it.
    wrap - Defaults to True. In case you use a Key derived class
           such as AsciiKey, specifies whether the signature data
           should be wrapped on return.
    *args, **kwargs - All extra arguments are passed to the
                      wrapping functions declared by the current
                      Key(-derived) class.

storeKey(self, wrap=True, *args, **kwargs)

Stores a key to a string of bytes. The arguments passed to this
function have the following meaning:
    
    wrap - Defaults to True. In case you use a Key derived class
           such as SecureKey or AsciiKey, specifies whether the
           keydata should be wrapped after storing it.
    *args, **kwargs - All extra arguments are passed to the
                      wrapping functions declared by the current
                      Key(-derived) class.

This function stores all key arguments to the key stream, even
when the key only contains a public key. In case the key contains
only a public key, the data is stored as PUBKEYDATA nevertheless
(even though private key arguments are stored to the stream), so
that e.g. SecureKey doesn't do encryption on the key. This means
that by using this function, you may leak private key arguments
that have been set on a public key (these are Untrusted anyway).

storePublicKey(self, wrap=True, *args, **kwargs)

Stores only the public key of this key to a string of bytes. The
arguments passed to this function have the following meaning:

    wrap - Defaults to True. In case you use a Key derived class
           such as SecureKey or AsciiKey, specifies whether the
           keydata should be wrapped after storing it.
    *args, **kwargs - All extra arguments are passed to the
                      wrapping functions declared by the current
                      Key(-derived) class.
                      
This function only stores public key arguments to the output
stream.

update(self, args)

Dictionary style updating for a Key instance. It allows you to set key arguments based on another Key instance, or based on any object supporting dictionary style interation and access.

verify(self, data, signature, wrap=True, *args, **kwargs)

Verify the signature of the passed in string. The signature must
have been created by the sign() method.

    data - String data to be verified.
    signature - Signature of the string data which was returned by
                the sign() function.
    wrap - Defaults to True. In case you use a Key derived class
           such as AsciiKey, specifies whether the signature data
           should be unwrapped before trying to verify it.
    *args, **kwargs - All extra arguments are passed to the
                      unwrapping functions declared by the current
                      Key(-derived) class.

Class Variable Details

id

Type:
property
Value:
<property object at 0x4022d39c>                                        

loadKey

Type:
classmethod
Value:
<classmethod object at 0x401b598c>                                     

Generated by Epydoc 1.1 on Sun Aug 17 03:32:32 2003 http://epydoc.sf.net