C# Class AnotherAES, code

Based on https://msdn.microsoft.com/en-us/library/system.security.cryptography.rijndaelmanaged(v=vs.110).aspx Uses UTF8 Encoding http://security.stackexchange.com/a/90850
Inheritance: IDisposable
Exibir arquivo Open project: shendongnian/code Class Usage Examples

Public Methods

Method Description
AnotherAES ( string key )

Initialize algo just with key Defaults for RijndaelManaged class: Block Size: 256 bits (32 bytes) Key Size: 128 bits (16 bytes) Padding Mode: PKCS7 Cipher Mode: CBC

AnotherAES ( string key, int blockSize, int keySize, PaddingMode, paddingMode, CipherMode, cipherMode )

Initialize algo with key, block size, key size, padding mode and cipher mode to be known.

Decrypt ( Array, cipherText, Array, IV ) : string

Based on https://msdn.microsoft.com/en-us/library/system.security.cryptography.rijndaelmanaged(v=vs.110).aspx

Dispose ( ) : void

Dispose RijndaelManaged object initialized in the constructor

Encrypt ( string plainText, Array, IV ) : byte[]

Based on https://msdn.microsoft.com/en-us/library/system.security.cryptography.rijndaelmanaged(v=vs.110).aspx Encrypt a string using RijndaelManaged encryptor.

GenerateEncryptionVector ( ) : byte[]

Generates a unique encryption vector using RijndaelManaged.GenerateIV() method

GetUniqueString ( int numBytes ) : string

Based on http://stackoverflow.com/a/1344255 Generate a unique string given number of bytes required. This string can be used as IV. IV byte size should be equal to cipher-block byte size. Allows seeing IV in plaintext so it can be passed along a url or some message.

StringToByteArray ( String hex ) : byte[]

Based on http://stackoverflow.com/a/311179/1541224 Converts a string to byte array. Useful when converting back hex string which was originally formed from bytes.

Method Details

AnotherAES() public method

Initialize algo just with key Defaults for RijndaelManaged class: Block Size: 256 bits (32 bytes) Key Size: 128 bits (16 bytes) Padding Mode: PKCS7 Cipher Mode: CBC
public AnotherAES ( string key )
key string

AnotherAES() public method

Initialize algo with key, block size, key size, padding mode and cipher mode to be known.
public AnotherAES ( string key, int blockSize, int keySize, PaddingMode, paddingMode, CipherMode, cipherMode )
key string ASCII key to be used for encryption or decryption
blockSize int block size to use for AES algorithm. 128, 192 or 256 bits (default for incorrect size=256)
keySize int key length to use for AES algorithm. 128, 192, or 256 bits (default for incorrect size=128)
paddingMode PaddingMode,
cipherMode CipherMode,

Decrypt() public method

Based on https://msdn.microsoft.com/en-us/library/system.security.cryptography.rijndaelmanaged(v=vs.110).aspx
public Decrypt ( Array, cipherText, Array, IV ) : string
cipherText Array, bytes to be decrypted back to plaintext
IV Array, initialization vector used to encrypt the bytes
return string

Dispose() public method

Dispose RijndaelManaged object initialized in the constructor
public Dispose ( ) : void
return void

Encrypt() public method

Based on https://msdn.microsoft.com/en-us/library/system.security.cryptography.rijndaelmanaged(v=vs.110).aspx Encrypt a string using RijndaelManaged encryptor.
public Encrypt ( string plainText, Array, IV ) : byte[]
plainText string string to be encrypted
IV Array, initialization vector to be used by crypto algorithm
return byte[]

GenerateEncryptionVector() public method

Generates a unique encryption vector using RijndaelManaged.GenerateIV() method
public GenerateEncryptionVector ( ) : byte[]
return byte[]

GetUniqueString() public static method

Based on http://stackoverflow.com/a/1344255 Generate a unique string given number of bytes required. This string can be used as IV. IV byte size should be equal to cipher-block byte size. Allows seeing IV in plaintext so it can be passed along a url or some message.
public static GetUniqueString ( int numBytes ) : string
numBytes int
return string

StringToByteArray() public static method

Based on http://stackoverflow.com/a/311179/1541224 Converts a string to byte array. Useful when converting back hex string which was originally formed from bytes.
public static StringToByteArray ( String hex ) : byte[]
hex String
return byte[]