Esempio n. 1
0
        static void Main(string[] args)
        {
            string plainText  = "Hello, World!";    // original plaintext
            string cipherText = "";                 // encrypted text
            string passPhrase = "Pas5pr@se";        // can be any string
            string initVector = "@1B2c3D4e5F6g7H8"; // must be 16 bytes

            // Before encrypting data, we will append plain text to a random
            // salt value, which will be between 4 and 8 bytes long (implicitly
            // used defaults).
            RijndaelEnhanced rijndaelKey =
                new RijndaelEnhanced(passPhrase, initVector);

            Console.WriteLine(String.Format("Plaintext   : {0}\n", plainText));

            // Encrypt the same plain text data 10 time (using the same key,
            // initialization vector, etc) and see the resulting cipher text;
            // encrypted values will be different.
            for (int i = 0; i < 10; i++)
            {
                cipherText = rijndaelKey.Encrypt(plainText);
                Console.WriteLine(
                    String.Format("Encrypted #{0}: {1}", i, cipherText));
                plainText = rijndaelKey.Decrypt(cipherText);
            }

            // Make sure we got decryption working correctly.
            Console.WriteLine(String.Format("\nDecrypted   :{0}", plainText));
        }
Esempio n. 2
0
        public static string ToEncryption(this string value)
        {
            if (string.IsNullOrEmpty(value))
            {
                return(string.Empty);
            }

            var e  = new RijndaelEnhanced(passPhrase, initVector);
            var en = e.Encrypt(value);

            return(en);
        }
Esempio n. 3
0
        public static string ToEncryption(this string value)
        {
            if (string.IsNullOrEmpty(value))
                return string.Empty;

            var e = new RijndaelEnhanced(passPhrase, initVector);
            var en = e.Encrypt(value);
            return en;
        }
Esempio n. 4
0
        static void Main(string[] args)
        {
            string plainText = "Hello, World!";    // original plaintext
            string cipherText = "";                 // encrypted text
            string passPhrase = "Pas5pr@se";        // can be any string
            string initVector = "@1B2c3D4e5F6g7H8"; // must be 16 bytes

            // Before encrypting data, we will append plain text to a random
            // salt value, which will be between 4 and 8 bytes long (implicitly
            // used defaults).
            RijndaelEnhanced rijndaelKey =
                new RijndaelEnhanced(passPhrase, initVector);

            Console.WriteLine(String.Format("Plaintext   : {0}\n", plainText));

            // Encrypt the same plain text data 10 time (using the same key,
            // initialization vector, etc) and see the resulting cipher text;
            // encrypted values will be different.
            for (int i = 0; i < 10; i++)
            {
                cipherText = rijndaelKey.Encrypt(plainText);
                Console.WriteLine(
                    String.Format("Encrypted #{0}: {1}", i, cipherText));
                plainText = rijndaelKey.Decrypt(cipherText);
            }

            // Make sure we got decryption working correctly.
            Console.WriteLine(String.Format("\nDecrypted   :{0}", plainText));
        }