Пример #1
0
        private static void AesTests2()
        {
            byte[] key = Encoding.UTF8.GetBytes("ABCD");
            using ProtectedMemory protectedKey = ProtectedMemory.Allocate(key.Length);
            protectedKey.Write(key, 0);
            ProtectedAesProvider aes    = new ProtectedAesProvider();
            const string         secret = "ABCDDCBA";

            Console.WriteLine("Original message:");
            Console.WriteLine(secret + "\n");
            string encrypted = aes.Encrypt(protectedKey, secret);

            Console.WriteLine("Encrypted message:");
            Console.WriteLine(encrypted + "\n");
            string decrypted = aes.Decrypt(protectedKey, encrypted);

            Console.WriteLine("Decrypted message:");
            Console.WriteLine(decrypted + "\n");
        }
Пример #2
0
        private static void AesTests()
        {
            byte[] key = Encoding.UTF8.GetBytes("ABCD");
            using ProtectedMemory protectedKey = ProtectedMemory.Allocate(key.Length);
            protectedKey.Write(key, 0);
            ProtectedAesProvider aes    = new ProtectedAesProvider();
            const string         secret = "0123456789ABCDEF";

            Console.WriteLine("Original message:");
            Console.WriteLine(secret + "\n");
            byte[] message = Encoding.UTF8.GetBytes(secret);
            using ProtectedMemory protectedMessage = ProtectedMemory.Allocate(message.Length);
            protectedMessage.Write(message, 0);
            string encrypted = aes.EncryptProtected(protectedKey, protectedMessage);

            Console.WriteLine("Encrypted message:");
            Console.WriteLine(encrypted + "\n");
            using ProtectedMemory protectedResult = aes.DecryptProtected(protectedKey, encrypted);
            byte[] result = protectedResult.Read(0, message.Length);
            Console.WriteLine("Decrypted message:");
            Console.WriteLine(Encoding.UTF8.GetString(result) + "\n");
        }