예제 #1
0
        public static byte[] Hash(byte[] message, byte[] key, int bytes)
        {
            int keyLength;

            if (key != null)
            {
                if (key.Length > 64 || key.Length < 16)
                {
                    throw new KeyOutOfRangeException(string.Format("key must be between {0} and {1} bytes in length.", 16, 64));
                }
                keyLength = key.Length;
            }
            else
            {
                key       = new byte[0];
                keyLength = 0;
            }
            if (bytes > 64 || bytes < 16)
            {
                throw new BytesOutOfRangeException("bytes", bytes, string.Format("bytes must be between {0} and {1} bytes in length.", 16, 64));
            }
            byte[] array = new byte[bytes];
            SodiumLibrary.crypto_generichash(array, array.Length, message, (long)message.Length, key, keyLength);
            return(array);
        }