CombineBytes() публичный статический Метод

Combines two byte arrays into one.

public static CombineBytes ( Byte buffer1, Byte buffer2 ) : Byte[]
buffer1 Byte The prefixed bytes.
buffer2 Byte The suffixed bytes.
Результат Byte[]
Пример #1
0
        private Boolean CompareHash(Type hashAlgorithmType, Byte[] plainText, Byte[] hashedBytes, Int32 saltLength = 16)
        {
            var hashAlgorithm = Activator.CreateInstance(hashAlgorithmType, true) as HashAlgorithm;

            if (hashAlgorithm == null)
            {
                throw new InvalidOperationException(String.Format("Could not create instance of type {0}.", hashAlgorithmType));
            }

            var salt       = CryptographyUtility.GetBytes(hashedBytes, saltLength);
            var targetHash = CryptographyUtility.CombineBytes(salt, hashAlgorithm.ComputeHash(CryptographyUtility.CombineBytes(salt, plainText)));

            return(CryptographyUtility.CompareBytes(hashedBytes, targetHash));
        }
Пример #2
0
        private Byte[] CreateHash(Type hashAlgorithmType, Byte[] plainText, Int32 saltLength = 16)
        {
            var hashAlgorithm = Activator.CreateInstance(hashAlgorithmType, true) as HashAlgorithm;

            if (hashAlgorithm == null)
            {
                throw new InvalidOperationException(String.Format("Could not create instance of type {0}.", hashAlgorithmType));
            }

            // Generate salt
            var salt = new Byte[saltLength];

            _RngCryptoServiceProvider.GetNonZeroBytes(salt);

            // Compute hash
            var hashedText = hashAlgorithm.ComputeHash(CryptographyUtility.CombineBytes(salt, plainText));

            // Randomize plain text
            _RngCryptoServiceProvider.GetBytes(plainText);

            return(CryptographyUtility.CombineBytes(salt, hashedText));
        }