C# Класс 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
Наследование: IDisposable
Показать файл Открыть проект Примеры использования класса

Открытые методы

Метод Описание
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.

Описание методов

AnotherAES() публичный Метод

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() публичный Метод

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() публичный Метод

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
Результат string

Dispose() публичный Метод

Dispose RijndaelManaged object initialized in the constructor
public Dispose ( ) : void
Результат void

Encrypt() публичный Метод

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
Результат byte[]

GenerateEncryptionVector() публичный Метод

Generates a unique encryption vector using RijndaelManaged.GenerateIV() method
public GenerateEncryptionVector ( ) : byte[]
Результат byte[]

GetUniqueString() публичный статический Метод

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
Результат string

StringToByteArray() публичный статический Метод

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
Результат byte[]