Class CryptoHelper
Crypography related helper methods.
Namespace: Neon.Cryptography
Assembly: Neon.Cryptography.dll
Syntax
public static class CryptoHelper
Fields
HMAC256ByteCount
The size of an HMAC256 in bytes.
Declaration
public const int HMAC256ByteCount = 32
Field Value
Type | Description |
---|---|
int |
HMAC512ByteCount
The size of an HMAC512 in bytes.
Declaration
public const int HMAC512ByteCount = 64
Field Value
Type | Description |
---|---|
int |
MD5ByteSize
The number of bytes in a MD5 hash.
Declaration
public const int MD5ByteSize = 16
Field Value
Type | Description |
---|---|
int |
SHA1ByteSize
The number of bytes in a SHA1 hash.
Declaration
public const int SHA1ByteSize = 20
Field Value
Type | Description |
---|---|
int |
SHA256ByteSize
The number of bytes in a SHA256 hash.
Declaration
public const int SHA256ByteSize = 32
Field Value
Type | Description |
---|---|
int |
SHA512ByteSize
The number of bytes in a SHA512 hash.
Declaration
public const int SHA512ByteSize = 64
Field Value
Type | Description |
---|---|
int |
Methods
ComputeMD5Bytes(byte[])
Computes the MD5 hash for a byte array and returns the result as a byte array.
Declaration
public static byte[] ComputeMD5Bytes(byte[] input)
Parameters
Type | Name | Description |
---|---|---|
byte[] | input | The input bytes. |
Returns
Type | Description |
---|---|
byte[] | The hash as a byte array. |
ComputeMD5Bytes(Stream)
Computes the MD5 hash for a stream from the current position until the end and returns the result as a byte array.
Declaration
public static byte[] ComputeMD5Bytes(Stream input)
Parameters
Type | Name | Description |
---|---|---|
Stream | input | The stream. |
Returns
Type | Description |
---|---|
byte[] | The hash as a byte array. |
ComputeMD5Bytes(string)
Computes the MD5 hash for a string and returns the result as a byte array.
Declaration
public static byte[] ComputeMD5Bytes(string input)
Parameters
Type | Name | Description |
---|---|---|
string | input | The input string. |
Returns
Type | Description |
---|---|
byte[] | The hash as a byte array. |
ComputeMD5BytesFromFile(string)
Computes the MD5 hash for file and returns the result returns the result as a byte array.
Declaration
public static byte[] ComputeMD5BytesFromFile(string path)
Parameters
Type | Name | Description |
---|---|---|
string | path | The source file path. |
Returns
Type | Description |
---|---|
byte[] | The hash as a byte array. |
ComputeMD5String(byte[])
Computes the MD5 hash for a byte array and returns the result formatted as a lowercase hex string.
Declaration
public static string ComputeMD5String(byte[] input)
Parameters
Type | Name | Description |
---|---|---|
byte[] | input | The input bytes. |
Returns
Type | Description |
---|---|
string | The hash as a HEX string. |
ComputeMD5String(Stream)
Computes the MD5 hash for a stream from the current position' until the end and returns the result formatted as a lowercase hex string.
Declaration
public static string ComputeMD5String(Stream input)
Parameters
Type | Name | Description |
---|---|---|
Stream | input | The stream. |
Returns
Type | Description |
---|---|
string | The hash as a HEX string. |
ComputeMD5String(string)
Computes the MD5 hash for a string and returns the result formatted as a lowercase hex string.
Declaration
public static string ComputeMD5String(string input)
Parameters
Type | Name | Description |
---|---|---|
string | input | The input string. |
Returns
Type | Description |
---|---|
string | The hash as a HEX string. |
ComputeMD5StringFromFile(string)
Computes the MD5 hash for file and returns the result formatted as a lowercase hex string.
Declaration
public static string ComputeMD5StringFromFile(string path)
Parameters
Type | Name | Description |
---|---|---|
string | path | The source file path. |
Returns
Type | Description |
---|---|
string | The hash as a HEX string. |
ComputeSHA1Bytes(byte[])
Computes the SHA1 hash for a byte array and returns the result as a byte array.
Declaration
public static byte[] ComputeSHA1Bytes(byte[] input)
Parameters
Type | Name | Description |
---|---|---|
byte[] | input | The input bytes. |
Returns
Type | Description |
---|---|
byte[] | The hash as a byte array. |
ComputeSHA1Bytes(Stream)
Computes the SHA1 hash for a stream from the current position' until the end and returns the result formatted as a lowercase hex string.
Declaration
public static byte[] ComputeSHA1Bytes(Stream input)
Parameters
Type | Name | Description |
---|---|---|
Stream | input | The stream. |
Returns
Type | Description |
---|---|
byte[] | The hash as a byte array. |
ComputeSHA1Bytes(string)
Computes the SHA1 hash for a string and returns the result as a byte array.
Declaration
public static byte[] ComputeSHA1Bytes(string input)
Parameters
Type | Name | Description |
---|---|---|
string | input | The input string. |
Returns
Type | Description |
---|---|
byte[] | The hash as a byte array. |
ComputeSHA1BytesFromFile(string)
Computes the SHA1 hash for file and returns the result returns the result as a byte array.
Declaration
public static byte[] ComputeSHA1BytesFromFile(string path)
Parameters
Type | Name | Description |
---|---|---|
string | path | The source file path. |
Returns
Type | Description |
---|---|
byte[] | The hash as a byte array. |
ComputeSHA1String(byte[])
Computes the SHA1 hash for a byte array and returns the result formatted as a lowercase hex string.
Declaration
public static string ComputeSHA1String(byte[] input)
Parameters
Type | Name | Description |
---|---|---|
byte[] | input | The input bytes. |
Returns
Type | Description |
---|---|
string | The hash as a HEX string. |
ComputeSHA1String(Stream)
Computes the SHA1 hash for a stream from the current position' until the end and returns the result formatted as a lowercase hex string.
Declaration
public static string ComputeSHA1String(Stream input)
Parameters
Type | Name | Description |
---|---|---|
Stream | input | The stream. |
Returns
Type | Description |
---|---|
string | The hash as a HEX string. |
ComputeSHA1String(string)
Computes the SHA1 hash for a string and returns the result formatted as a lowercase hex string.
Declaration
public static string ComputeSHA1String(string input)
Parameters
Type | Name | Description |
---|---|---|
string | input | The input string. |
Returns
Type | Description |
---|---|
string | The hash as a HEX string. |
ComputeSHA1StringFromFile(string)
Computes the SHA1 hash for file and returns the result formatted as a lowercase hex string.
Declaration
public static string ComputeSHA1StringFromFile(string path)
Parameters
Type | Name | Description |
---|---|---|
string | path | The source file path. |
Returns
Type | Description |
---|---|
string | The hash as a HEX string. |
ComputeSHA256Bytes(byte[])
Computes the SHA256 hash for a byte array and returns the result as a byte array.
Declaration
public static byte[] ComputeSHA256Bytes(byte[] input)
Parameters
Type | Name | Description |
---|---|---|
byte[] | input | The input bytes. |
Returns
Type | Description |
---|---|
byte[] | The hash as a byte array. |
ComputeSHA256Bytes(Stream)
Computes the SHA256 hash for a stream from the current position' until the end and returns the result formatted as a lowercase hex string.
Declaration
public static byte[] ComputeSHA256Bytes(Stream input)
Parameters
Type | Name | Description |
---|---|---|
Stream | input | The stream. |
Returns
Type | Description |
---|---|
byte[] | The hash as a byte array. |
ComputeSHA256Bytes(string)
Computes the SHA256 hash for a string and returns the result as a byte array.
Declaration
public static byte[] ComputeSHA256Bytes(string input)
Parameters
Type | Name | Description |
---|---|---|
string | input | The input string. |
Returns
Type | Description |
---|---|
byte[] | The hash as a byte array. |
ComputeSHA256BytesFromFile(string)
Computes the SHA256 hash for file and returns the result returns the result as a byte array.
Declaration
public static byte[] ComputeSHA256BytesFromFile(string path)
Parameters
Type | Name | Description |
---|---|---|
string | path | The source file path. |
Returns
Type | Description |
---|---|
byte[] | The hash as a byte array. |
ComputeSHA256String(byte[])
Computes the SHA256 hash for a byte array and returns the result formatted as a lowercase hex string.
Declaration
public static string ComputeSHA256String(byte[] input)
Parameters
Type | Name | Description |
---|---|---|
byte[] | input | The input bytes. |
Returns
Type | Description |
---|---|
string | The hash as a HEX string. |
ComputeSHA256String(Stream)
Computes the SHA256 hash for a stream from the current position' until the end and returns the result formatted as a lowercase hex string.
Declaration
public static string ComputeSHA256String(Stream input)
Parameters
Type | Name | Description |
---|---|---|
Stream | input | The stream. |
Returns
Type | Description |
---|---|
string | The hash as a HEX string. |
ComputeSHA256String(string)
Computes the SHA256 hash for a string and returns the result formatted as a lowercase hex string.
Declaration
public static string ComputeSHA256String(string input)
Parameters
Type | Name | Description |
---|---|---|
string | input | The input string. |
Returns
Type | Description |
---|---|
string | The hash as a HEX string. |
ComputeSHA256StringFromFile(string)
Computes the SHA256 hash for file and returns the result formatted as a lowercase hex string.
Declaration
public static string ComputeSHA256StringFromFile(string path)
Parameters
Type | Name | Description |
---|---|---|
string | path | The source file path. |
Returns
Type | Description |
---|---|
string | The hash as a HEX string. |
ComputeSHA512Bytes(byte[])
Computes the SHA512 hash for a byte array and returns the result as a byte array.
Declaration
public static byte[] ComputeSHA512Bytes(byte[] input)
Parameters
Type | Name | Description |
---|---|---|
byte[] | input | The input bytes. |
Returns
Type | Description |
---|---|
byte[] | The hash bytes. |
ComputeSHA512Bytes(Stream)
Computes the SHA512 hash for a stream from the current position' until the end and returns the result formatted as a lowercase hex string.
Declaration
public static byte[] ComputeSHA512Bytes(Stream input)
Parameters
Type | Name | Description |
---|---|---|
Stream | input | The stream. |
Returns
Type | Description |
---|---|
byte[] | The hash as a byte array. |
ComputeSHA512Bytes(string)
Computes the SHA512 hash for a string and returns the result as a byte array.
Declaration
public static byte[] ComputeSHA512Bytes(string input)
Parameters
Type | Name | Description |
---|---|---|
string | input | The input string. |
Returns
Type | Description |
---|---|
byte[] | The hash as a byte array. |
ComputeSHA512BytesFromFile(string)
Computes the SHA512 hash for file and returns the result returns the result as a byte array.
Declaration
public static byte[] ComputeSHA512BytesFromFile(string path)
Parameters
Type | Name | Description |
---|---|---|
string | path | The source file path. |
Returns
Type | Description |
---|---|
byte[] | The hash as a byte array. |
ComputeSHA512String(byte[])
Computes the SHA512 hash for a byte array and returns the result formatted as a lowercase hex string.
Declaration
public static string ComputeSHA512String(byte[] input)
Parameters
Type | Name | Description |
---|---|---|
byte[] | input | The input bytes. |
Returns
Type | Description |
---|---|
string | The hash as a HEX string. |
ComputeSHA512String(Stream)
Computes the SHA512 hash for a stream from the current position' until the end and returns the result formatted as a lowercase hex string.
Declaration
public static string ComputeSHA512String(Stream input)
Parameters
Type | Name | Description |
---|---|---|
Stream | input | The stream. |
Returns
Type | Description |
---|---|
string | The hash as a HEX string. |
ComputeSHA512String(string)
Computes the SHA512 hash for a string and returns the result formatted as a lowercase hex string.
Declaration
public static string ComputeSHA512String(string input)
Parameters
Type | Name | Description |
---|---|---|
string | input | The input string. |
Returns
Type | Description |
---|---|
string | The hash as a HEX string. |
ComputeSHA512StringFromFile(string)
Computes the SHA512 hash for file and returns the result formatted as a lowercase hex string.
Declaration
public static string ComputeSHA512StringFromFile(string path)
Parameters
Type | Name | Description |
---|---|---|
string | path | The source file path. |
Returns
Type | Description |
---|---|
string | The hash as a HEX string. |
DeriveKeyFromPassword(string, int)
Generates a symmetric encryption key from a password string.
Declaration
public static byte[] DeriveKeyFromPassword(string password, int keySize)
Parameters
Type | Name | Description |
---|---|---|
string | password | The input password. |
int | keySize | The desired key size in bits (this must be less than or equal to 512 and be a factor of 8). |
Returns
Type | Description |
---|---|
byte[] | The derived key. |