Skip to content

Common Security

Ivan Kozhin edited this page Jun 19, 2020 · 4 revisions

1. MD5

string MD5(string target)

Produces 128-bit hash value of the string. PHP-compliant. The security of the MD5 hash function is severely compromised. It is not recommended for password hashing and provided only for backward compatibility.

2. Sha1

string Sha1(string target)

Produces 160-bit hash value of the string. The most widely used hashing algorithm. It is not recommended to use it for hashing now.

3. Sha256

string Sha256(string target)

Produces 256-bit hash value of the string. The variant of SHA-2. It provides good security for password hashing.

4. Sha384

string Sha384(string target)

Produces 384-bit hash value of the string. The variant of SHA-2. It provides good security for password hashing.

5. Sha512

string Sha512(string target)

Produces 512-bit hash value of the string. The variant of SHA-2. It provides very good security for password hashing.

6. Pbkdf2Sha1

byte[] Pbkdf2Sha1(string target, int numOfIterations);
byte[] Pbkdf2Sha1(string target, byte[] salt, int numOfIterations);

Returns PBKDF2 compatible hash by using a pseudo-random number generator based on HMACSHA1. The default number of iterations is 10000.

7. Hash

string Hash(string target, HashMethods method)

Hash string with the selected hash method. The string will contain a method name that was used for hashing. Possible methods are Md5, Sha1, Sha256, Sha384, Sha512, Pbkdf2Sha1.

8. CheckHash

bool CheckHash(string target, string hashedStringToCheck)

Compares target string with hashed string.

9. Crc32

uint Crc32(byte[] target, uint polynomial, uint seedCrc)

Returns CRC-32 checksum. By default uses IEEE polynomial. Possible polynomials to use:

  • Crc32Ieee (default)
  • Crc32Castagnoli
  • Crc32Koopman

10. Crc64

ulong Crc64(byte[] target, ulong polynomial, ulong seedCrc)

Returns the CRC-64 checksum of data using the polynomial. The default implementation uses ISO polynomial. Possible polynomials to use:

  • Crc64IsoPolynomial (default)
  • Crc64EcmaPolynomial

11. ConvertBytesToString

string ConvertBytesToString(byte[] bytes)

Convert an array of bytes to string representation. Replace dashes with empty strings.

12. ConvertStringToBytes

byte[] ConvertStringToBytes(string target)

Convert string that contains hex representation of bytes to bytes array.

Clone this wiki locally