Table of Contents

Class CryptoHelper

Namespace
Ecng.Security
Assembly
Ecng.Security.dll

Crypto helper.

public static class CryptoHelper
Inheritance
CryptoHelper
Inherited Members

Methods

CreateSecret(SecureString)

Creates a new Secret from the plain text.

public static Secret CreateSecret(this SecureString plainText)

Parameters

plainText SecureString

The plain text.

Returns

Secret

Secret

CreateSecret(string)

Creates a new Secret from the plain text.

public static Secret CreateSecret(this string plainText)

Parameters

plainText string

The plain text.

Returns

Secret

Secret

CreateSecret(string, Secret)

Creates a new Secret from the plain text.

public static Secret CreateSecret(this string plainText, Secret secret)

Parameters

plainText string

The plain text.

secret Secret

Secret

Returns

Secret

Secret

CreateSecret(string, byte[], CryptoAlgorithm)

Creates a new Secret from the plain text.

public static Secret CreateSecret(this string plainText, byte[] salt, CryptoAlgorithm algo = null)

Parameters

plainText string

The plain text.

salt byte[]

The salt.

algo CryptoAlgorithm

The hash algorithm.

Returns

Secret

Secret

Decrypt(byte[], string, byte[], byte[])

Decrypts the cipher text.

public static byte[] Decrypt(this byte[] cipherText, string passPhrase, byte[] salt, byte[] iv)

Parameters

cipherText byte[]

The cipher text.

passPhrase string

The pass phrase.

salt byte[]

The salt.

iv byte[]

The iv.

Returns

byte[]

The decrypted bytes.

DecryptAes(byte[], string, byte[], byte[])

Decrypts the cipher text.

public static byte[] DecryptAes(this byte[] cipherText, string passPhrase, byte[] salt, byte[] iv)

Parameters

cipherText byte[]

The cipher text.

passPhrase string

The pass phrase.

salt byte[]

The salt.

iv byte[]

The iv.

Returns

byte[]

The plain text.

Encrypt(byte[], string, byte[], byte[])

Encrypts the plain text.

public static byte[] Encrypt(this byte[] plain, string passPhrase, byte[] salt, byte[] iv)

Parameters

plain byte[]

The plain text.

passPhrase string

The pass phrase.

salt byte[]

The salt.

iv byte[]

The iv.

Returns

byte[]

The encrypted bytes.

EncryptAes(byte[], string, byte[], byte[])

Encrypts the plain text.

public static byte[] EncryptAes(this byte[] plain, string passPhrase, byte[] salt, byte[] iv)

Parameters

plain byte[]

The plain text.

passPhrase string

The pass phrase.

salt byte[]

The salt.

iv byte[]

The iv.

Returns

byte[]

The cipher text.

FromRsa(RSAParameters)

Converts the RSAParameters to a byte array.

public static byte[] FromRsa(this RSAParameters param)

Parameters

param RSAParameters

RSAParameters

Returns

byte[]

Byte array.

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 RSAParameters GenerateRsa()

Returns

RSAParameters

IsValid(Secret, SecureString)

Validates the password.

public static bool IsValid(this Secret secret, SecureString password)

Parameters

secret Secret

Secret

password SecureString

The password to check.

Returns

bool

Operation result.

IsValid(Secret, string)

Validates the password.

public static bool IsValid(this Secret secret, string password)

Parameters

secret Secret

Secret

password string

The password to check.

Returns

bool

Operation result.

Md5(byte[])

MD5 hash.

public static string Md5(this byte[] value)

Parameters

value byte[]

The value to hash.

Returns

string

The hash.

PublicPart(RSAParameters)

Returns the public part of the RSAParameters.

public static RSAParameters PublicPart(this RSAParameters param)

Parameters

param RSAParameters

RSAParameters

Returns

RSAParameters

The public part of the RSAParameters.

Sha256(byte[])

SHA1 hash.

public static string Sha256(this byte[] value)

Parameters

value byte[]

The value to hash.

Returns

string

The hash.

Sha512(byte[])

SHA512 hash.

public static string Sha512(this byte[] value)

Parameters

value byte[]

The value to hash.

Returns

string

The hash.

ToRsa(byte[])

Converts the byte array to RSAParameters.

public static RSAParameters ToRsa(this byte[] key)

Parameters

key byte[]

Byte array.

Returns

RSAParameters

RSAParameters