C# Class FlexiWebSDK.Crypto.BlowfishCrypt

Inheritance: ICryptProvider
Show file Open project: FlexiDB/PublicCSharpLib

Public Methods

Method Description
BlowfishCrypt ( ) : System
BlowfishCrypt ( byte cipherKey ) : System

Constructor for byte key

BlowfishCrypt ( string hexKey ) : System

Constructor for hex key

Crypt_CTR ( byte text, int numThreads ) : byte[]
Decrypt ( string ct ) : string
Decrypt_CBC ( byte ct ) : byte[]

Decrypts a byte array in CBC mode. IV must be created and saved manually.

Decrypt_CBC ( string ct ) : string

Decrypts a string in CBC mode

Decrypt_CTR ( string ct ) : string

Decrypt a string (CTR)

Decrypt_ECB ( byte ct ) : byte[]

Decrypts a byte array (ECB)

Decrypt_ECB ( string ct ) : string

Decrypts a string (ECB)

Encrypt ( string pt ) : string
Encrypt_CBC ( byte pt ) : byte[]

Encrypts a byte array in CBC mode. IV must be created and saved manually.

Encrypt_CBC ( string pt ) : string

Encrypts a string in CBC mode

Encrypt_CTR ( string pt ) : string

Encrypts a string (CTR)

Encrypt_ECB ( byte pt ) : byte[]

Encrypts a byte array in ECB mode

Encrypt_ECB ( string pt ) : string

Encrypt a string in ECB mode

SetKey ( byte key ) : void
SetKey ( string key ) : void
SetRandomIV ( ) : byte[]

Creates and sets a random initialization vector.

Private Methods

Method Description
BlockDecrypt ( byte &block ) : void

Decrypts a 64 bit block

BlockEncrypt ( byte &block ) : void

Encrypts a 64 bit block

ByteToHex ( byte bytes ) : string
Crypt_CBC ( byte text, bool decrypt ) : byte[]

Encrypts or decrypts data in CBC mode

Crypt_ECB ( byte text, bool decrypt ) : byte[]

Encrypts or decrypts data in ECB mode

GetBlock ( byte &block ) : void

Converts the two uint values into a 64 bit block

GetHex ( char x ) : byte
HexToByte ( string hex ) : byte[]
SetBlock ( byte block ) : void

Splits the block into the two uint values

SetupKey ( byte cipherKey ) : void

Sets up the S-blocks and the key

SetupP ( ) : uint[]
SetupS0 ( ) : uint[]
SetupS1 ( ) : uint[]
SetupS2 ( ) : uint[]
SetupS3 ( ) : uint[]
XorBlock ( byte &block, byte iv ) : void

XoR encrypts two 8 bit blocks

decipher ( ) : void

Runs the blowfish algorithm in reverse (standard 16 rounds)

encipher ( ) : void

Runs the blowfish algorithm (standard 16 rounds)

round ( uint a, uint b, uint n ) : uint

one round of the blowfish algorithm

wordByte0 ( uint w ) : byte
wordByte1 ( uint w ) : byte
wordByte2 ( uint w ) : byte
wordByte3 ( uint w ) : byte

Method Details

BlowfishCrypt() public method

public BlowfishCrypt ( ) : System
return System

BlowfishCrypt() public method

Constructor for byte key
public BlowfishCrypt ( byte cipherKey ) : System
cipherKey byte Cipher key as a byte array
return System

BlowfishCrypt() public method

Constructor for hex key
public BlowfishCrypt ( string hexKey ) : System
hexKey string Cipher key as a hex string
return System

Crypt_CTR() public method

public Crypt_CTR ( byte text, int numThreads ) : byte[]
text byte
numThreads int
return byte[]

Decrypt() public method

public Decrypt ( string ct ) : string
ct string
return string

Decrypt_CBC() public method

Decrypts a byte array in CBC mode. IV must be created and saved manually.
public Decrypt_CBC ( byte ct ) : byte[]
ct byte Ciphertext data to decrypt
return byte[]

Decrypt_CBC() public method

Decrypts a string in CBC mode
public Decrypt_CBC ( string ct ) : string
ct string Ciphertext with IV appended to front
return string

Decrypt_CTR() public method

Decrypt a string (CTR)
public Decrypt_CTR ( string ct ) : string
ct string The ciphertext to decrypt
return string

Decrypt_ECB() public method

Decrypts a byte array (ECB)
public Decrypt_ECB ( byte ct ) : byte[]
ct byte Ciphertext byte array
return byte[]

Decrypt_ECB() public method

Decrypts a string (ECB)
public Decrypt_ECB ( string ct ) : string
ct string hHex string of the ciphertext
return string

Encrypt() public method

public Encrypt ( string pt ) : string
pt string
return string

Encrypt_CBC() public method

Encrypts a byte array in CBC mode. IV must be created and saved manually.
public Encrypt_CBC ( byte pt ) : byte[]
pt byte Plaintext data to encrypt
return byte[]

Encrypt_CBC() public method

Encrypts a string in CBC mode
public Encrypt_CBC ( string pt ) : string
pt string Plaintext data to encrypt
return string

Encrypt_CTR() public method

Encrypts a string (CTR)
public Encrypt_CTR ( string pt ) : string
pt string The plaintext to encrypt
return string

Encrypt_ECB() public method

Encrypts a byte array in ECB mode
public Encrypt_ECB ( byte pt ) : byte[]
pt byte Plaintext data
return byte[]

Encrypt_ECB() public method

Encrypt a string in ECB mode
public Encrypt_ECB ( string pt ) : string
pt string Plaintext to encrypt as ascii string
return string

SetKey() public method

public SetKey ( byte key ) : void
key byte
return void

SetKey() public method

public SetKey ( string key ) : void
key string
return void

SetRandomIV() public method

Creates and sets a random initialization vector.
public SetRandomIV ( ) : byte[]
return byte[]