示例#1
0
        public static ReadOnlySpan <byte> DoubleSha512(ReadOnlySpan <byte> data)
        {
            using var sha = new SHA512Managed();
            Span <byte> result = new byte[64];

            sha.TryComputeHash(data, result, out _);
            sha.TryComputeHash(result, result, out _);
            return(result.Slice(0, 32));
        }
示例#2
0
 public static Core.DataTypes.UInt256 DoubleSha512AsUInt256(ReadOnlySpan <byte> data)
 {
     using (var sha = new SHA512Managed())
     {
         Span <byte> result = stackalloc byte[64];
         sha.TryComputeHash(data, result, out _);
         sha.TryComputeHash(result, result, out _);
         return(new Core.DataTypes.UInt256(result.Slice(0, 32)));
     }
 }
        public static UInt256 DoubleSha512AsUInt256(ReadOnlySpan <byte> data)
        {
            using var sha = new SHA512Managed();
            Span <byte> result = stackalloc byte[64];

            if (!sha.TryComputeHash(data, result, out _))
            {
                throw new HashGeneratorException($"Failed to perform {nameof(DoubleSha512AsUInt256)}");
            }
            if (!sha.TryComputeHash(result, result, out _))
            {
                throw new HashGeneratorException($"Failed to perform {nameof(DoubleSha512AsUInt256)}");
            }
            return(new UInt256(result.Slice(0, 32)));
        }
示例#4
0
        public static int HashSHA512(ReadOnlySpan <byte> src, Span <byte> dest)
        {
            SHA512 sha = new SHA512Managed();

            if (sha.TryComputeHash(src, dest, out int ret) == false)
            {
                throw new ApplicationException("TryComputeHash error.");
            }

            return(ret);
        }
示例#5
0
        private void Hash(string password, ReadOnlySpan <byte> salt, Span <byte> output)
        {
            if (password.Length > MAX_PASSWORD_LENGTH)
            {
                return;
            }
            Span <byte> input = stackalloc byte[salt.Length + MAX_PASSWORD_LENGTH + pepper.Length];

            salt.CopyTo(input);
            Encoding.UTF8.GetBytes(password, input.Slice(salt.Length));
            pepper.CopyTo(input.Slice(salt.Length + password.Length));
            using var sha512 = new SHA512Managed();
            sha512.TryComputeHash(input.Slice(0, salt.Length + password.Length + pepper.Length), output, out var _);
        }
示例#6
0
 public static Boolean Sha512(ReadOnlySpan <Byte> data, Span <Byte> destination, out Int32 written)
 {
     using SHA512 sha512 = new SHA512Managed();
     return(sha512.TryComputeHash(data, destination, out written));
 }