CryptoHelper
Crypto helper.
Methods
public static Secret CreatePasswordSecret(string password, byte[] salt)
result = CryptoHelper.CreatePasswordSecret(password, salt)
Creates a password Secret using PBKDF2 (slow, salted key stretching) — the recommended way to store passwords, unlike the fast single-pass CryptoAlgorithm).
- password
- The plain-text password.
- salt
- Optional salt; a random one is generated when omitted.
Returns: Secret whose Hash is the PBKDF2 derivation.
public static Secret CreateSecret(string plainText, byte[] salt, CryptoAlgorithm algo)
result = CryptoHelper.CreateSecret(plainText, salt, algo)
Creates a new Secret from the plain text.
- plainText
- The plain text.
- salt
- The salt.
- algo
- The hash algorithm.
Returns: Secret
public static Secret CreateSecret(string plainText, Secret secret, CryptoAlgorithm algo)
result = CryptoHelper.CreateSecret(plainText, secret, algo)
Creates a new Secret from the plain text.
- plainText
- The plain text.
- secret
- Secret
- algo
- The hash algorithm.
Returns: Secret
public static Secret CreateSecret(string plainText, CryptoAlgorithm algo)
result = CryptoHelper.CreateSecret(plainText, algo)
Creates a new Secret from the plain text.
- plainText
- The plain text.
- algo
- The hash algorithm.
Returns: Secret
public static Secret CreateSecret(SecureString plainText, CryptoAlgorithm algo)
result = CryptoHelper.CreateSecret(plainText, algo)
Creates a new Secret from the plain text.
- plainText
- The plain text.
- algo
- The hash algorithm.
Returns: Secret
public static byte[] Decrypt(byte[] cipherText, string passPhrase, byte[] salt, byte[] iv)
result = CryptoHelper.Decrypt(cipherText, passPhrase, salt, iv)
Decrypts the cipher text.
- cipherText
- The cipher text.
- passPhrase
- The pass phrase.
- salt
- The salt.
- iv
- The iv.
Returns: The decrypted bytes.
public static byte[] DecryptAes(byte[] cipherText, string passPhrase, byte[] salt, byte[] iv)
result = CryptoHelper.DecryptAes(cipherText, passPhrase, salt, iv)
Decrypts the cipher text.
- cipherText
- The cipher text.
- passPhrase
- The pass phrase.
- salt
- The salt.
- iv
- The iv.
Returns: The plain text.
public static byte[] Encrypt(byte[] plain, string passPhrase, byte[] salt, byte[] iv)
result = CryptoHelper.Encrypt(plain, passPhrase, salt, iv)
Encrypts the plain text.
- plain
- The plain text.
- passPhrase
- The pass phrase.
- salt
- The salt.
- iv
- The iv.
Returns: The encrypted bytes.
public static byte[] EncryptAes(byte[] plain, string passPhrase, byte[] salt, byte[] iv)
result = CryptoHelper.EncryptAes(plain, passPhrase, salt, iv)
Encrypts the plain text.
- plain
- The plain text.
- passPhrase
- The pass phrase.
- salt
- The salt.
- iv
- The iv.
Returns: The cipher text.
public static byte[] FromRsa(RSAParameters param)
result = CryptoHelper.FromRsa(param)
Converts the RSAParameters to a byte array.
- param
- RSAParameters
Returns: Byte array.
public static RSAParameters GenerateRsa()
result = CryptoHelper.GenerateRsa()
Returns a new generated RSAParameters class which will be used as a key for the signature. It will generate a PRIVATE key (which includes the PUBLIC key).
public static bool IsPasswordValid(Secret secret, string password)
result = CryptoHelper.IsPasswordValid(secret, password)
Validates a password against a PBKDF2 Secret created by Byte[]), in constant time.
- secret
- Secret.
- password
- The password to check.
Returns: if the password matches.
public static bool IsValid(Secret secret, string password, CryptoAlgorithm algo)
result = CryptoHelper.IsValid(secret, password, algo)
Validates the password.
- secret
- Secret
- password
- The password to check.
- algo
- The hash algorithm.
Returns: Operation result.
public static bool IsValid(Secret secret, SecureString password, CryptoAlgorithm algo)
result = CryptoHelper.IsValid(secret, password, algo)
Validates the password.
- secret
- Secret
- password
- The password to check.
- algo
- The hash algorithm.
Returns: Operation result.
public static string Md5(byte[] value)
result = CryptoHelper.Md5(value)
MD5 hash.
- value
- The value to hash.
Returns: The hash.
public static RSAParameters PublicPart(RSAParameters param)
result = CryptoHelper.PublicPart(param)
Returns the public part of the RSAParameters.
- param
- RSAParameters
Returns: The public part of the RSAParameters.
public static string Sha256(byte[] value)
result = CryptoHelper.Sha256(value)
SHA256 hash.
- value
- The value to hash.
Returns: The hash.
public static string Sha512(byte[] value)
result = CryptoHelper.Sha512(value)
SHA512 hash.
- value
- The value to hash.
Returns: The hash.
public static RSAParameters ToRsa(byte[] key)
result = CryptoHelper.ToRsa(key)
Converts the byte array to RSAParameters.
- key
- Byte array.
Returns: RSAParameters
Fields
public const int DefaultSaltSize
value = CryptoHelper.DefaultSaltSize
The default salt size.
public const int PasswordIterations
value = CryptoHelper.PasswordIterations
Number of PBKDF2 iterations used to hash passwords (key stretching).