Module yawPyCrypto.AdvKey
AdvKey.py
=========
AsciiKey
--------
Key class which wraps key data and encryption/signature packets in base64
encoding. This class offers exactly the same functionality that the
underlying Key class offers, and is a drop-in replacement. The packets it
generates have a similar look and feel as GPG ascii-armored packets, with
a header and a footer (which is configurable through several class
members). If you wish to convert any key object to an AsciiKey, call the
toAsciiKey function.
SecureKey
---------
Key class which wraps private key data in an encryption packet with the
block cipher algorithm Blowfish. This class offers exactly the same
functionality that the underlying Key class offers, and is a drop-in
replacement. The returned packets are byte strings, just as the key class.
If you wish to convert any key object to a SecureKey, call the toSecureKey
function.
SecureAsciiKey
--------------
Key class which combines wrapping key data and encryption/signature
packets in base64 encoding, while encrypting private key data first
with the block cipher Blowfish. This class offers exactly the same
functionality that the underlying Key class offers, and is a drop-in
replacement. The packets it generates have a similar look and feel as
GPG ascii-armored packets, with a header and a footer (which is
configurable through several class members). If you wish to convert any
key object to a SecureAsciiKey, call the toSecureAsciiKey function.
Writing your own Key extension classes
--------------------------------------
It is quite simple to write your own key extension classes, which do
data wrapping in a user-specified format. The first thing to do is to
define two functions, which have reverse effects, one to wrap data in
your personal format, one to unwrap the data from this format.
The functions should be defined similar to the following:
def _wrap(selfcls,data,datatype,*args,**kwargs):
<wrap data>
return <wrapped data>
def _unwrap(selfcls,data,datatype,*args,**kwargs):
<unwrap data>
return <unwrapped data>
The parameters these functions take are:
1. selfcls, the Key class on which the method which does
wrapping/unwrapping is called. Thus, if you declare the
functions as class members, they have to be classmethods.
2. data, the data which is to be wrapped or unwrapped. This is a
string. The function should change this string to a more suitable
format, and return the changed data.
3. datatype, one of the PRIVKEYDATA, PUBKEYDATA, ENCDATA, SIGNDATA
constants defined in the Key module, which specify the type of data
that is being wrapped. This can be used to add specific headers to
the data (as demonstrated in the _asciiWrap() and _asciiUnwrap()
functions). You can also use this to only wrap specific packets.
Sidenote: On unwrapping key data, PRIVKEYDATA is always used when
unwrapping keys, as it is not known whether the key is only a public
key when the unwrapping is being done. On wrapping key data, one of
PRIVKEYDATA and PUBKEYDATA is passed in depending on whether
storeKey() or storePublicKey() is called and whether the key contains
a public key.
4. *args, **kwargs, all extra arguments that are passed to the
function which calls the wrapper/unwrapper. These can be used at free
will by the function. An example is the SecureKey class, which expects
to be passed a password which is used to protect the key as a keyword
argument called password.
The class also needs to define two class members called _wrappers and
_unwrappers, which are lists of tuples. These lists specify the wrapping
functions to be called, and the order in which they are called. The tuples
have to be in the format: (<priority>,<function to call>). <Priority> is a
number, where functions with a lower priority are called earlier, while
<function to call> is simply a reference to the function which is to be
called.
Further questions on writing Key extension classes?
---------------------------------------------------
Read the source, luke. The source should be self-documentary enough to get
you started quickly.
Copyright
=========
yawPyCrypto is copyright (C) 2002-3 by Heiko Wundram
<heiko@asta.uni-saarland.de>.
This library is free software; you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or (at
your option) any later version.
This library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this library in the file "COPYLEFT"; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA
Classes |
AsciiKey |
AsciiKey is a Key derived class which offers functionality to wrap Key
data in base64 encoded packets. |
SecureAsciiKey |
SecureAsciiKey is a Key derived class which offers both ascii-armoring
and also encryption of private key data in a single key class. |
SecureKey |
SecureKey is a Key derived class which offers encryption of private
key data using the Blowfish cipher, with a specified password. |
Function Summary |
|
toAsciiKey (key)
Changes the passed in key so that it now is an instance of
AsciiKey. |
|
toSecureAsciiKey (key)
Changes the passed in key so that it now is an instance of
SecureAsciiKey. |
|
toSecureKey (key)
Changes the passed in key so that it now is an instance of
SecureKey. |
toAsciiKey(key)
Changes the passed in key so that it now is an instance of AsciiKey.
This can be transparently done with any key instance. Returned values
will now be ascii wrapped if this key is used.
-
|
toSecureAsciiKey(key)
Changes the passed in key so that it now is an instance of
SecureAsciiKey. This can be transparently done with any key instance.
Returned values will now be ascii wrapped, and private key data is
encrypted with a password.
-
|
toSecureKey(key)
Changes the passed in key so that it now is an instance of SecureKey.
This can be transparently done with any key instance. Returned private
key data will now be encrypted with a specified password.
-
|
__date__
-
- Type:
-
str
- Value:
|
__version__
-
- Type:
-
str
- Value:
|
CIPHER_AES
-
- Type:
-
int
- Value:
|
CIPHER_ARC2
-
- Type:
-
int
- Value:
|
CIPHER_ARC4
-
- Type:
-
int
- Value:
|
CIPHER_BLOWFISH
-
- Type:
-
int
- Value:
|
CIPHER_CAST
-
- Type:
-
int
- Value:
|
CIPHER_DES3
-
- Type:
-
int
- Value:
|
CIPHERALGO
-
- Type:
-
int
- Value:
|
HASH_MD2
-
- Type:
-
int
- Value:
|
HASH_MD4
-
- Type:
-
int
- Value:
|
HASH_MD5
-
- Type:
-
int
- Value:
|
HASH_NONE
-
- Type:
-
int
- Value:
|
HASH_SHA
-
- Type:
-
int
- Value:
|
HASHALGO
-
- Type:
-
int
- Value:
|
HAVE_AES
-
- Type:
-
bool
- Value:
|
HAVE_ARC2
-
- Type:
-
bool
- Value:
|
HAVE_ARC4
-
- Type:
-
bool
- Value:
|
HAVE_BLOWFISH
-
- Type:
-
bool
- Value:
|
HAVE_CAST
-
- Type:
-
bool
- Value:
|
HAVE_DES3
-
- Type:
-
bool
- Value:
|
HAVE_DSA
-
- Type:
-
bool
- Value:
|
HAVE_ELGAMAL
-
- Type:
-
bool
- Value:
|
HAVE_IDEA
-
- Type:
-
bool
- Value:
|
HAVE_MD2
-
- Type:
-
bool
- Value:
|
HAVE_MD4
-
- Type:
-
bool
- Value:
|
HAVE_MD5
-
- Type:
-
bool
- Value:
|
HAVE_QNEW
-
- Type:
-
bool
- Value:
|
HAVE_RC5
-
- Type:
-
bool
- Value:
|
HAVE_RIPEMD
-
- Type:
-
bool
- Value:
|
HAVE_RSA
-
- Type:
-
bool
- Value:
|
HAVE_SHA
-
- Type:
-
bool
- Value:
|
LOAD_INSECURE_CIPHER_ALGOS
-
- Type:
-
int
- Value:
|
MODE_CBC
-
- Type:
-
int
- Value:
|
MODE_CFB
-
- Type:
-
int
- Value:
|
MODE_CTR
-
- Type:
-
int
- Value:
|
MODE_ECB
-
- Type:
-
int
- Value:
|
MODE_NONE
-
- Type:
-
int
- Value:
|
MODE_OFB
-
- Type:
-
int
- Value:
|
MODE_PGP
-
- Type:
-
int
- Value:
|
PRIVKEYDATA
-
- Type:
-
int
- Value:
|
PUBKEYDATA
-
- Type:
-
int
- Value:
|
PUBLICKEY_DSA
-
- Type:
-
int
- Value:
|
PUBLICKEY_ELGAMAL
-
- Type:
-
int
- Value:
|
PUBLICKEY_QNEW
-
- Type:
-
int
- Value:
|
PUBLICKEY_RSA
-
- Type:
-
int
- Value:
|
SIGNDATA
-
- Type:
-
int
- Value:
|