Ejemplo n.º 1
0
        //[Fact] - Keeping this test for reference but we don't want to run it as an inner-loop test because
        //         it creates a key on disk.
        public static void AesRoundTrip256BitsNoneECBUsingStoredKey()
        {
            CngAlgorithm algname = new CngAlgorithm("AES");
            string       keyName = "CoreFxTest-" + Guid.NewGuid();
            CngKey       _cngKey = CngKey.Create(algname, keyName);

            try
            {
                using (Aes alg = new AesCng(keyName))
                {
                    try
                    {
                        alg.Padding = PaddingMode.None;
                        alg.Mode    = CipherMode.ECB;

                        int keySize = alg.KeySize;

                        byte[] plainText         = "15a818701f0f7c99fe4b1b4b860f131b".HexToByteArray();
                        byte[] cipher            = alg.Encrypt(plainText);
                        byte[] decrypted         = alg.Decrypt(cipher);
                        byte[] expectedDecrypted = "15a818701f0f7c99fe4b1b4b860f131b".HexToByteArray();
                        Assert.Equal <byte>(expectedDecrypted, decrypted);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.Message);
                    }
                }
            }
            finally
            {
                _cngKey.Delete();
            }
        }