コード例 #1
0
ファイル: Program.cs プロジェクト: mart610k/HashingH4
        private static void EncryptWithHmac(Encrypter encrypter)
        {
            Console.WriteLine("Encrypting HMAC With the hashing Alorithm " + encrypter.HashingAlgo);
            Console.Write("Message to Encrypt: ");
            string messageToEncrypt = Console.ReadLine();

            Console.Write("Key to Encrypt with (blank for generating random key) base64 format: ");
            string keyToEncryptWith = Console.ReadLine();

            byte[] key = null;
            try
            {
                key = Convert.FromBase64String(keyToEncryptWith);
            }
            catch
            {
                Console.WriteLine("Could not convert user inputted string as Base64, generating random key");
                keyToEncryptWith = "";
            }

            if (keyToEncryptWith == "")
            {
                key = encrypter.GenerateKey(32);
            }

            Console.WriteLine("Message(Base64): " + Convert.ToBase64String(encrypter.ComputeMacWithKey(Encoding.UTF8.GetBytes(messageToEncrypt), key)));
            Console.WriteLine("Key(Base64): " + Convert.ToBase64String(key));
        }