Ejemplo n.º 1
0
        public byte[] DecryptData(EncryptedPacket EP, RsaWithRsaParameterKey rsaParams)
        {
            // Receiver decrypts AES session key with RSA
            byte[] decryptedSessionKey = rsaParams.DecryptData(EP.EncryptedSessionKey);

            // Receiver decrypts the data wuth AES using the decrypted session key
            byte[] decryptedData = _cryptographyExample.DecryptUsingAES(EP.EncryptedData, decryptedSessionKey, EP.IV);

            return(decryptedData);
        }
Ejemplo n.º 2
0
        private void RunEncryptionUsingAES()
        {
            Console.WriteLine("Encryption Using AES started");
            Console.WriteLine();

            CryptographyExample cryptographyExample = new CryptographyExample();

            // here we are creating a key that is 32 bytes in length or 256 bits, which is the max size of an AES key
            byte[] key = cryptographyExample.GenerateRandomNumber(32);

            // AES using a 16 byte Initialization Vector
            byte[]       initializationVector = cryptographyExample.GenerateRandomNumber(16);
            const string originalMessage      = "Text To Encrypt";

            Console.WriteLine(String.Format("Message before encryption: {0}", originalMessage));

            byte[] encryptedMessage = cryptographyExample.EncryptUsingAES(Encoding.UTF8.GetBytes(originalMessage), key, initializationVector);
            Console.WriteLine(String.Format("Message after encryption: {0}", Encoding.UTF8.GetString(encryptedMessage)));

            byte[] decryptedMessage = cryptographyExample.DecryptUsingAES(encryptedMessage, key, initializationVector);
            Console.WriteLine(String.Format("Message after decryption: {0}", Encoding.UTF8.GetString(decryptedMessage)));

            Console.WriteLine();
            Console.WriteLine("Encryption Using AES ended");
        }