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

Module yawPyCrypto.Cipher

Cipher.py

EncryptCipher

Stream encryption wrapper class. This class offers an encryption stream with a known password (passed as a parameter at object initialization time). Passing data to the stream is done using the feed() method, when encryption has finished, you need to call finish() to close the stream.

DecryptCipher

Stream decryption wrapper class. This class offers decryption of streams generated by the EncryptCipher class. These streams are fed to the decryption by calling the feed() method, and when the stream is finished, it is necessary to call the finish() method of the stream object, which checks for stream end and flushes all pending output.

ZipEn/DecryptCipher

Classes which expose a similar interface as EncryptCipher and DecryptCipher, but which additionally to doing encryption compress the passed in byte-stream on encryption, and decompress it on decryption. This makes the data which is actually stored in the encrypted stream more "random", which most security experts recommend as a security bonus. These classes are only defined if USE_ZLIB is defined as True in the configuration file.

Interface of cipher classes

The interface of the cipher classes is simple. On encryption, you pass a password (the encryption key), the cipher algorithm to use, the cipher mode to use, and an optional hash algorithm which is used to create a checksum of the data that is in the byte-stream. All this information is stored in the encryption stream (which should be of no concern, as it's not the chosen algorithm that makes encryption safe, but the password). On decryption, this information is read, and an appropriate stream for decryption is automatically created, so that decryption only needs the password that was used for encryption.

The encryption and decryption classes have a similar interface which concerns feeding data to the object. Calling feed() will feed more data into the stream, possibly encrypting/decrypting some of it directly when the call is made. Calling finish() will close the stream on encryption and write out the final blocks, while on decryption the stream end condition is checked.

Data which has been created by the encryption/decryption routines is stored for retrieval in the property data of the instance, retrieving the value of this property will empty the current output buffer.

Overriding of methods

The most import method you can override of any *Cipher class is _writeOutput(self,data). This method is called by the cipher code to put available output into the buffer from which data is retrieved. In case you want to connect the encryption directly to a file or the like, it may be feasible to override this method, and directly write the passed data to the output file/socket/whatever.

You can override several other methods to create your own stream handling capabilities or to add stream wrapping (which is also done by overriding the _writeOutput() method. Please see the documentation for AdvCipher for a complete overview on how to achieve this.

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
DecryptCipher Decryption cipher class.
EncryptCipher Encryption cipher class.
ZipDecryptCipher Class which works similar to DecryptCipher, but streams all data read from the encrypted stream through unzipping on reading.
ZipEncryptCipher Class which works similar to EncryptCipher, but streams all data through zipping on writing, so that it is in effect "randomized" on writing.

Variable Summary
str __date__
str __version__
int CIPHER_AES
int CIPHER_ARC2
int CIPHER_ARC4
int CIPHER_BLOWFISH
int CIPHER_CAST
int CIPHER_DES3
int HASH_MD2
int HASH_MD4
int HASH_MD5
int HASH_NONE
int HASH_SHA
bool HAVE_AES
bool HAVE_ARC2
bool HAVE_ARC4
bool HAVE_BLOWFISH
bool HAVE_CAST
bool HAVE_DES3
bool HAVE_DSA
bool HAVE_ELGAMAL
bool HAVE_IDEA
bool HAVE_MD2
bool HAVE_MD4
bool HAVE_MD5
bool HAVE_QNEW
bool HAVE_RC5
bool HAVE_RIPEMD
bool HAVE_RSA
bool HAVE_SHA
int LOAD_INSECURE_CIPHER_ALGOS
int MODE_CBC
int MODE_CFB
int MODE_CTR
int MODE_ECB
int MODE_NONE
int MODE_OFB
int MODE_PGP
int PUBLICKEY_DSA
int PUBLICKEY_ELGAMAL
int PUBLICKEY_QNEW
int PUBLICKEY_RSA
bool USE_ZLIB

Variable Details

__date__

Type:
str
Value:
'2003/08/16'                                                           

__version__

Type:
str
Value:
'0.1p5'                                                                

CIPHER_AES

Type:
int
Value:
0                                                                      

CIPHER_ARC2

Type:
int
Value:
1                                                                      

CIPHER_ARC4

Type:
int
Value:
2                                                                      

CIPHER_BLOWFISH

Type:
int
Value:
3                                                                      

CIPHER_CAST

Type:
int
Value:
4                                                                      

CIPHER_DES3

Type:
int
Value:
6                                                                      

HASH_MD2

Type:
int
Value:
1                                                                      

HASH_MD4

Type:
int
Value:
2                                                                      

HASH_MD5

Type:
int
Value:
3                                                                      

HASH_NONE

Type:
int
Value:
0                                                                      

HASH_SHA

Type:
int
Value:
5                                                                      

HAVE_AES

Type:
bool
Value:
True                                                                   

HAVE_ARC2

Type:
bool
Value:
True                                                                   

HAVE_ARC4

Type:
bool
Value:
True                                                                   

HAVE_BLOWFISH

Type:
bool
Value:
True                                                                   

HAVE_CAST

Type:
bool
Value:
True                                                                   

HAVE_DES3

Type:
bool
Value:
True                                                                   

HAVE_DSA

Type:
bool
Value:
True                                                                   

HAVE_ELGAMAL

Type:
bool
Value:
True                                                                   

HAVE_IDEA

Type:
bool
Value:
False                                                                  

HAVE_MD2

Type:
bool
Value:
True                                                                   

HAVE_MD4

Type:
bool
Value:
True                                                                   

HAVE_MD5

Type:
bool
Value:
True                                                                   

HAVE_QNEW

Type:
bool
Value:
True                                                                   

HAVE_RC5

Type:
bool
Value:
False                                                                  

HAVE_RIPEMD

Type:
bool
Value:
False                                                                  

HAVE_RSA

Type:
bool
Value:
True                                                                   

HAVE_SHA

Type:
bool
Value:
True                                                                   

LOAD_INSECURE_CIPHER_ALGOS

Type:
int
Value:
0                                                                      

MODE_CBC

Type:
int
Value:
1                                                                      

MODE_CFB

Type:
int
Value:
2                                                                      

MODE_CTR

Type:
int
Value:
3                                                                      

MODE_ECB

Type:
int
Value:
4                                                                      

MODE_NONE

Type:
int
Value:
0                                                                      

MODE_OFB

Type:
int
Value:
5                                                                      

MODE_PGP

Type:
int
Value:
6                                                                      

PUBLICKEY_DSA

Type:
int
Value:
0                                                                      

PUBLICKEY_ELGAMAL

Type:
int
Value:
1                                                                      

PUBLICKEY_QNEW

Type:
int
Value:
2                                                                      

PUBLICKEY_RSA

Type:
int
Value:
3                                                                      

USE_ZLIB

Type:
bool
Value:
True                                                                   

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