C# Class InvertedSoftware.WorkflowEngine.Common.Security.RijndaelEnhanced

Afficher le fichier Open project: invertedsoftware/Inverted-Software-Workflow-Engine Class Usage Examples

Méthodes publiques

Méthode Description
Decrypt ( byte cipherTextBytes ) : string

Decrypts a byte array containing cipher text value and generates a string result.

Decrypt ( string cipherText ) : string

Decrypts a base64-encoded cipher text value generating a string result.

DecryptToBytes ( byte cipherTextBytes ) : byte[]

Decrypts a base64-encoded cipher text value and generates a byte array of plain text data.

DecryptToBytes ( string cipherText ) : byte[]

Decrypts a base64-encoded cipher text value and generates a byte array of plain text data.

Encrypt ( byte plainTextBytes ) : string

Encrypts a byte array generating a base64-encoded string.

Encrypt ( string plainText ) : string

Encrypts a string value generating a base64-encoded string.

EncryptToBytes ( byte plainTextBytes ) : byte[]

Encrypts a byte array generating a byte array of cipher text.

EncryptToBytes ( string plainText ) : byte[]

Encrypts a string value generating a byte array of cipher text.

RijndaelEnhanced ( string passPhrase ) : System

Use this constructor if you are planning to perform encryption/ decryption with 256-bit key, derived using 1 password iteration, hashing without salt, no initialization vector, electronic codebook (ECB) mode, SHA-1 hashing algorithm, and 4-to-8 byte long salt.

This constructor is not recommended because it does not use initialization vector and uses the ECB cipher mode, which is less secure than the CBC mode.

RijndaelEnhanced ( string passPhrase, string initVector ) : System

Use this constructor if you are planning to perform encryption/ decryption with 256-bit key, derived using 1 password iteration, hashing without salt, cipher block chaining (CBC) mode, SHA-1 hashing algorithm, and 4-to-8 byte long salt.

RijndaelEnhanced ( string passPhrase, string initVector, int minSaltLen ) : System

Use this constructor if you are planning to perform encryption/ decryption with 256-bit key, derived using 1 password iteration, hashing without salt, cipher block chaining (CBC) mode, SHA-1 hashing algorithm, and 0-to-8 byte long salt.

RijndaelEnhanced ( string passPhrase, string initVector, int minSaltLen, int maxSaltLen ) : System

Use this constructor if you are planning to perform encryption/ decryption with 256-bit key, derived using 1 password iteration, hashing without salt, cipher block chaining (CBC) mode, SHA-1 hashing algorithm. Use the minSaltLen and maxSaltLen parameters to specify the size of randomly generated salt.

RijndaelEnhanced ( string passPhrase, string initVector, int minSaltLen, int maxSaltLen, int keySize ) : System

Use this constructor if you are planning to perform encryption/ decryption using the key derived from 1 password iteration, hashing without salt, cipher block chaining (CBC) mode, and SHA-1 hashing algorithm.

RijndaelEnhanced ( string passPhrase, string initVector, int minSaltLen, int maxSaltLen, int keySize, string hashAlgorithm ) : System

Use this constructor if you are planning to perform encryption/ decryption using the key derived from 1 password iteration, hashing without salt, and cipher block chaining (CBC) mode.

RijndaelEnhanced ( string passPhrase, string initVector, int minSaltLen, int maxSaltLen, int keySize, string hashAlgorithm, string saltValue ) : System

Use this constructor if you are planning to perform encryption/ decryption using the key derived from 1 password iteration, and cipher block chaining (CBC) mode.

RijndaelEnhanced ( string passPhrase, string initVector, int minSaltLen, int maxSaltLen, int keySize, string hashAlgorithm, string saltValue, int passwordIterations ) : System

Use this constructor if you are planning to perform encryption/ decryption with the key derived from the explicitly specified parameters.

Private Methods

Méthode Description
AddSalt ( byte plainTextBytes ) : byte[]

Adds an array of randomly generated bytes at the beginning of the array holding original plain text value.

GenerateRandomNumber ( int minValue, int maxValue ) : int

Generates random integer.

This methods overcomes the limitations of .NET Framework's Random class, which - when initialized multiple times within a very short period of time - can generate the same "random" number.

GenerateSalt ( ) : byte[]

Generates an array holding cryptographically strong bytes.

Salt size will be defined at random or exactly as specified by the minSlatLen and maxSaltLen parameters passed to the object constructor. The first four bytes of the salt array will contain the salt length split into four two-bit pieces.

Method Details

Decrypt() public méthode

Decrypts a byte array containing cipher text value and generates a string result.
public Decrypt ( byte cipherTextBytes ) : string
cipherTextBytes byte /// Byte array containing encrypted data. ///
Résultat string

Decrypt() public méthode

Decrypts a base64-encoded cipher text value generating a string result.
public Decrypt ( string cipherText ) : string
cipherText string /// Base64-encoded cipher text string to be decrypted. ///
Résultat string

DecryptToBytes() public méthode

Decrypts a base64-encoded cipher text value and generates a byte array of plain text data.
public DecryptToBytes ( byte cipherTextBytes ) : byte[]
cipherTextBytes byte /// Byte array containing encrypted data. ///
Résultat byte[]

DecryptToBytes() public méthode

Decrypts a base64-encoded cipher text value and generates a byte array of plain text data.
public DecryptToBytes ( string cipherText ) : byte[]
cipherText string /// Base64-encoded cipher text string to be decrypted. ///
Résultat byte[]

Encrypt() public méthode

Encrypts a byte array generating a base64-encoded string.
public Encrypt ( byte plainTextBytes ) : string
plainTextBytes byte /// Plain text bytes to be encrypted. ///
Résultat string

Encrypt() public méthode

Encrypts a string value generating a base64-encoded string.
public Encrypt ( string plainText ) : string
plainText string /// Plain text string to be encrypted. ///
Résultat string

EncryptToBytes() public méthode

Encrypts a byte array generating a byte array of cipher text.
public EncryptToBytes ( byte plainTextBytes ) : byte[]
plainTextBytes byte /// Plain text bytes to be encrypted. ///
Résultat byte[]

EncryptToBytes() public méthode

Encrypts a string value generating a byte array of cipher text.
public EncryptToBytes ( string plainText ) : byte[]
plainText string /// Plain text string to be encrypted. ///
Résultat byte[]

RijndaelEnhanced() public méthode

Use this constructor if you are planning to perform encryption/ decryption with 256-bit key, derived using 1 password iteration, hashing without salt, no initialization vector, electronic codebook (ECB) mode, SHA-1 hashing algorithm, and 4-to-8 byte long salt.
This constructor is not recommended because it does not use initialization vector and uses the ECB cipher mode, which is less secure than the CBC mode.
public RijndaelEnhanced ( string passPhrase ) : System
passPhrase string /// Passphrase from which a pseudo-random password will be derived. /// The derived password will be used to generate the encryption key. /// Passphrase can be any string. In this example we assume that the /// passphrase is an ASCII string. Passphrase value must be kept in /// secret. ///
Résultat System

RijndaelEnhanced() public méthode

Use this constructor if you are planning to perform encryption/ decryption with 256-bit key, derived using 1 password iteration, hashing without salt, cipher block chaining (CBC) mode, SHA-1 hashing algorithm, and 4-to-8 byte long salt.
public RijndaelEnhanced ( string passPhrase, string initVector ) : System
passPhrase string /// Passphrase from which a pseudo-random password will be derived. /// The derived password will be used to generate the encryption key. /// Passphrase can be any string. In this example we assume that the /// passphrase is an ASCII string. Passphrase value must be kept in /// secret. ///
initVector string /// Initialization vector (IV). This value is required to encrypt the /// first block of plaintext data. For RijndaelManaged class IV must be /// exactly 16 ASCII characters long. IV value does not have to be kept /// in secret. ///
Résultat System

RijndaelEnhanced() public méthode

Use this constructor if you are planning to perform encryption/ decryption with 256-bit key, derived using 1 password iteration, hashing without salt, cipher block chaining (CBC) mode, SHA-1 hashing algorithm, and 0-to-8 byte long salt.
public RijndaelEnhanced ( string passPhrase, string initVector, int minSaltLen ) : System
passPhrase string /// Passphrase from which a pseudo-random password will be derived. /// The derived password will be used to generate the encryption key /// Passphrase can be any string. In this example we assume that the /// passphrase is an ASCII string. Passphrase value must be kept in /// secret. ///
initVector string /// Initialization vector (IV). This value is required to encrypt the /// first block of plaintext data. For RijndaelManaged class IV must be /// exactly 16 ASCII characters long. IV value does not have to be kept /// in secret. ///
minSaltLen int /// Min size (in bytes) of randomly generated salt which will be added at /// the beginning of plain text before encryption is performed. When this /// value is less than 4, the default min value will be used (currently 4 /// bytes). ///
Résultat System

RijndaelEnhanced() public méthode

Use this constructor if you are planning to perform encryption/ decryption with 256-bit key, derived using 1 password iteration, hashing without salt, cipher block chaining (CBC) mode, SHA-1 hashing algorithm. Use the minSaltLen and maxSaltLen parameters to specify the size of randomly generated salt.
public RijndaelEnhanced ( string passPhrase, string initVector, int minSaltLen, int maxSaltLen ) : System
passPhrase string /// Passphrase from which a pseudo-random password will be derived. /// The derived password will be used to generate the encryption key. /// Passphrase can be any string. In this example we assume that the /// passphrase is an ASCII string. Passphrase value must be kept in /// secret. ///
initVector string /// Initialization vector (IV). This value is required to encrypt the /// first block of plaintext data. For RijndaelManaged class IV must be /// exactly 16 ASCII characters long. IV value does not have to be kept /// in secret. ///
minSaltLen int /// Min size (in bytes) of randomly generated salt which will be added at /// the beginning of plain text before encryption is performed. When this /// value is less than 4, the default min value will be used (currently 4 /// bytes). ///
maxSaltLen int /// Max size (in bytes) of randomly generated salt which will be added at /// the beginning of plain text before encryption is performed. When this /// value is negative or greater than 255, the default max value will be /// used (currently 8 bytes). If max value is 0 (zero) or if it is smaller /// than the specified min value (which can be adjusted to default value), /// salt will not be used and plain text value will be encrypted as is. /// In this case, salt will not be processed during decryption either. ///
Résultat System

RijndaelEnhanced() public méthode

Use this constructor if you are planning to perform encryption/ decryption using the key derived from 1 password iteration, hashing without salt, cipher block chaining (CBC) mode, and SHA-1 hashing algorithm.
public RijndaelEnhanced ( string passPhrase, string initVector, int minSaltLen, int maxSaltLen, int keySize ) : System
passPhrase string /// Passphrase from which a pseudo-random password will be derived. /// The derived password will be used to generate the encryption key. /// Passphrase can be any string. In this example we assume that the /// passphrase is an ASCII string. Passphrase value must be kept in /// secret. ///
initVector string /// Initialization vector (IV). This value is required to encrypt the /// first block of plaintext data. For RijndaelManaged class IV must be /// exactly 16 ASCII characters long. IV value does not have to be kept /// in secret. ///
minSaltLen int /// Min size (in bytes) of randomly generated salt which will be added at /// the beginning of plain text before encryption is performed. When this /// value is less than 4, the default min value will be used (currently 4 /// bytes). ///
maxSaltLen int /// Max size (in bytes) of randomly generated salt which will be added at /// the beginning of plain text before encryption is performed. When this /// value is negative or greater than 255, the default max value will be /// used (currently 8 bytes). If max value is 0 (zero) or if it is smaller /// than the specified min value (which can be adjusted to default value), /// salt will not be used and plain text value will be encrypted as is. /// In this case, salt will not be processed during decryption either. ///
keySize int /// Size of symmetric key (in bits): 128, 192, or 256. ///
Résultat System

RijndaelEnhanced() public méthode

Use this constructor if you are planning to perform encryption/ decryption using the key derived from 1 password iteration, hashing without salt, and cipher block chaining (CBC) mode.
public RijndaelEnhanced ( string passPhrase, string initVector, int minSaltLen, int maxSaltLen, int keySize, string hashAlgorithm ) : System
passPhrase string /// Passphrase from which a pseudo-random password will be derived. /// The derived password will be used to generate the encryption key. /// Passphrase can be any string. In this example we assume that the /// passphrase is an ASCII string. Passphrase value must be kept in /// secret. ///
initVector string /// Initialization vector (IV). This value is required to encrypt the /// first block of plaintext data. For RijndaelManaged class IV must be /// exactly 16 ASCII characters long. IV value does not have to be kept /// in secret. ///
minSaltLen int /// Min size (in bytes) of randomly generated salt which will be added at /// the beginning of plain text before encryption is performed. When this /// value is less than 4, the default min value will be used (currently 4 /// bytes). ///
maxSaltLen int /// Max size (in bytes) of randomly generated salt which will be added at /// the beginning of plain text before encryption is performed. When this /// value is negative or greater than 255, the default max value will be /// used (currently 8 bytes). If max value is 0 (zero) or if it is smaller /// than the specified min value (which can be adjusted to default value), /// salt will not be used and plain text value will be encrypted as is. /// In this case, salt will not be processed during decryption either. ///
keySize int /// Size of symmetric key (in bits): 128, 192, or 256. ///
hashAlgorithm string /// Hashing algorithm: "MD5" or "SHA1". SHA1 is recommended. ///
Résultat System

RijndaelEnhanced() public méthode

Use this constructor if you are planning to perform encryption/ decryption using the key derived from 1 password iteration, and cipher block chaining (CBC) mode.
public RijndaelEnhanced ( string passPhrase, string initVector, int minSaltLen, int maxSaltLen, int keySize, string hashAlgorithm, string saltValue ) : System
passPhrase string /// Passphrase from which a pseudo-random password will be derived. /// The derived password will be used to generate the encryption key. /// Passphrase can be any string. In this example we assume that the /// passphrase is an ASCII string. Passphrase value must be kept in /// secret. ///
initVector string /// Initialization vector (IV). This value is required to encrypt the /// first block of plaintext data. For RijndaelManaged class IV must be /// exactly 16 ASCII characters long. IV value does not have to be kept /// in secret. ///
minSaltLen int /// Min size (in bytes) of randomly generated salt which will be added at /// the beginning of plain text before encryption is performed. When this /// value is less than 4, the default min value will be used (currently 4 /// bytes). ///
maxSaltLen int /// Max size (in bytes) of randomly generated salt which will be added at /// the beginning of plain text before encryption is performed. When this /// value is negative or greater than 255, the default max value will be /// used (currently 8 bytes). If max value is 0 (zero) or if it is smaller /// than the specified min value (which can be adjusted to default value), /// salt will not be used and plain text value will be encrypted as is. /// In this case, salt will not be processed during decryption either. ///
keySize int /// Size of symmetric key (in bits): 128, 192, or 256. ///
hashAlgorithm string /// Hashing algorithm: "MD5" or "SHA1". SHA1 is recommended. ///
saltValue string /// Salt value used for password hashing during key generation. This is /// not the same as the salt we will use during encryption. This parameter /// can be any string. ///
Résultat System

RijndaelEnhanced() public méthode

Use this constructor if you are planning to perform encryption/ decryption with the key derived from the explicitly specified parameters.
public RijndaelEnhanced ( string passPhrase, string initVector, int minSaltLen, int maxSaltLen, int keySize, string hashAlgorithm, string saltValue, int passwordIterations ) : System
passPhrase string /// Passphrase from which a pseudo-random password will be derived. /// The derived password will be used to generate the encryption key /// Passphrase can be any string. In this example we assume that the /// passphrase is an ASCII string. Passphrase value must be kept in /// secret. ///
initVector string /// Initialization vector (IV). This value is required to encrypt the /// first block of plaintext data. For RijndaelManaged class IV must be /// exactly 16 ASCII characters long. IV value does not have to be kept /// in secret. ///
minSaltLen int /// Min size (in bytes) of randomly generated salt which will be added at /// the beginning of plain text before encryption is performed. When this /// value is less than 4, the default min value will be used (currently 4 /// bytes). ///
maxSaltLen int /// Max size (in bytes) of randomly generated salt which will be added at /// the beginning of plain text before encryption is performed. When this /// value is negative or greater than 255, the default max value will be /// used (currently 8 bytes). If max value is 0 (zero) or if it is smaller /// than the specified min value (which can be adjusted to default value), /// salt will not be used and plain text value will be encrypted as is. /// In this case, salt will not be processed during decryption either. ///
keySize int /// Size of symmetric key (in bits): 128, 192, or 256. ///
hashAlgorithm string /// Hashing algorithm: "MD5" or "SHA1". SHA1 is recommended. ///
saltValue string /// Salt value used for password hashing during key generation. This is /// not the same as the salt we will use during encryption. This parameter /// can be any string. ///
passwordIterations int /// Number of iterations used to hash password. More iterations are /// considered more secure but may take longer. ///
Résultat System