CryptoHelper

Ecng.Security

Crypto helper.

メソッド

CreatePasswordSecret
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.

戻り値: Secret whose Hash is the PBKDF2 derivation.

CreateSecret
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.

戻り値: Secret

CreateSecret
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.

戻り値: Secret

CreateSecret
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.

戻り値: Secret

CreateSecret
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.

戻り値: Secret

Decrypt
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.

戻り値: The decrypted bytes.

DecryptAes
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.

戻り値: The plain text.

Encrypt
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.

戻り値: The encrypted bytes.

EncryptAes
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.

戻り値: The cipher text.

FromRsa
public static byte[] FromRsa(RSAParameters param)
result = CryptoHelper.FromRsa(param)

Converts the RSAParameters to a byte array.

param
RSAParameters

戻り値: Byte array.

GenerateRsa
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).

IsPasswordValid
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.

戻り値: if the password matches.

IsValid
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.

戻り値: Operation result.

IsValid
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.

戻り値: Operation result.

Md5
public static string Md5(byte[] value)
result = CryptoHelper.Md5(value)

MD5 hash.

value
The value to hash.

戻り値: The hash.

PublicPart
public static RSAParameters PublicPart(RSAParameters param)
result = CryptoHelper.PublicPart(param)

Returns the public part of the RSAParameters.

param
RSAParameters

戻り値: The public part of the RSAParameters.

Sha256
public static string Sha256(byte[] value)
result = CryptoHelper.Sha256(value)

SHA256 hash.

value
The value to hash.

戻り値: The hash.

Sha512
public static string Sha512(byte[] value)
result = CryptoHelper.Sha512(value)

SHA512 hash.

value
The value to hash.

戻り値: The hash.

ToRsa
public static RSAParameters ToRsa(byte[] key)
result = CryptoHelper.ToRsa(key)

Converts the byte array to RSAParameters.

key
Byte array.

戻り値: RSAParameters

フィールド

DefaultSaltSize
public const int DefaultSaltSize
value = CryptoHelper.DefaultSaltSize

The default salt size.

PasswordIterations
public const int PasswordIterations
value = CryptoHelper.PasswordIterations

Number of PBKDF2 iterations used to hash passwords (key stretching).