C# Class Crisis.Ionic.Zip.ZipCrypto

This class implements the "traditional" or "classic" PKZip encryption, which today is considered to be weak. On the other hand it is ubiquitous. This class is intended for use only by the DotNetZip library.
Most uses of the DotNetZip library will not involve direct calls into the ZipCrypto class. Instead, the ZipCrypto class is instantiated and used by the ZipEntry() class when encryption or decryption on an entry is employed. If for some reason you really wanted to use a weak encryption algorithm in some other application, you might use this library. But you would be much better off using one of the built-in strong encryption libraries in the .NET Framework, like the AES algorithm or SHA.
Show file Open project: teeknofil/Crisis-Wordlist-Generator Class Usage Examples

Private Properties

Property Type Description
UpdateKeys void
ZipCrypto System

Public Methods

Method Description
DecryptMessage ( byte cipherText, int length ) : byte[]

Call this method on a cipher text to render the plaintext. You must first initialize the cipher with a call to InitCipher.

EncryptMessage ( byte plainText, int length ) : byte[]

This is the converse of DecryptMessage. It encrypts the plaintext and produces a ciphertext.

ForRead ( string password, ZipEntry e ) : ZipCrypto
ForWrite ( string password ) : ZipCrypto
InitCipher ( string passphrase ) : void

This initializes the cipher with the given password. See AppNote.txt for details.

Step 1 - Initializing the encryption keys ----------------------------------------- Start with these keys: Key(0) := 305419896 (0x12345678) Key(1) := 591751049 (0x23456789) Key(2) := 878082192 (0x34567890) Then, initialize the keys with a password: loop for i from 0 to length(password)-1 update_keys(password(i)) end loop Where update_keys() is defined as: update_keys(char): Key(0) := crc32(key(0),char) Key(1) := Key(1) + (Key(0) bitwiseAND 000000ffH) Key(1) := Key(1) * 134775813 + 1 Key(2) := crc32(key(2),key(1) rightshift 24) end update_keys Where crc32(old_crc,char) is a routine that given a CRC value and a character, returns an updated CRC value after applying the CRC-32 algorithm described elsewhere in this document.

After the keys are initialized, then you can use the cipher to encrypt the plaintext.

Essentially we encrypt the password with the keys, then discard the ciphertext for the password. This initializes the keys for later use.

Private Methods

Method Description
UpdateKeys ( byte byteValue ) : void
ZipCrypto ( ) : System

The default constructor for ZipCrypto.

This class is intended for internal use by the library only. It's probably not useful to you. Seriously. Stop reading this documentation. It's a waste of your time. Go do something else. Check the football scores. Go get an ice cream with a friend. Seriously.

Method Details

DecryptMessage() public method

Call this method on a cipher text to render the plaintext. You must first initialize the cipher with a call to InitCipher.
public DecryptMessage ( byte cipherText, int length ) : byte[]
cipherText byte The encrypted buffer.
length int /// The number of bytes to encrypt. /// Should be less than or equal to CipherText.Length. ///
return byte[]

EncryptMessage() public method

This is the converse of DecryptMessage. It encrypts the plaintext and produces a ciphertext.
public EncryptMessage ( byte plainText, int length ) : byte[]
plainText byte The plain text buffer.
length int /// The number of bytes to encrypt. /// Should be less than or equal to plainText.Length. ///
return byte[]

ForRead() public static method

public static ForRead ( string password, ZipEntry e ) : ZipCrypto
password string
e ZipEntry
return ZipCrypto

ForWrite() public static method

public static ForWrite ( string password ) : ZipCrypto
password string
return ZipCrypto

InitCipher() public method

This initializes the cipher with the given password. See AppNote.txt for details.
Step 1 - Initializing the encryption keys ----------------------------------------- Start with these keys: Key(0) := 305419896 (0x12345678) Key(1) := 591751049 (0x23456789) Key(2) := 878082192 (0x34567890) Then, initialize the keys with a password: loop for i from 0 to length(password)-1 update_keys(password(i)) end loop Where update_keys() is defined as: update_keys(char): Key(0) := crc32(key(0),char) Key(1) := Key(1) + (Key(0) bitwiseAND 000000ffH) Key(1) := Key(1) * 134775813 + 1 Key(2) := crc32(key(2),key(1) rightshift 24) end update_keys Where crc32(old_crc,char) is a routine that given a CRC value and a character, returns an updated CRC value after applying the CRC-32 algorithm described elsewhere in this document.

After the keys are initialized, then you can use the cipher to encrypt the plaintext.

Essentially we encrypt the password with the keys, then discard the ciphertext for the password. This initializes the keys for later use.

public InitCipher ( string passphrase ) : void
passphrase string /// The passphrase for encrypting or decrypting with this cipher. ///
return void