Example #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));
        }
Example #2
0
        public static string ToDecryption(this string value)
        {
            if (string.IsNullOrEmpty(value))
                return string.Empty;

            var e = new RijndaelEnhanced(passPhrase, initVector);
            var removeSalt = value.Replace(salt, "");
            return e.Decrypt(removeSalt);
        }
Example #3
0
        public static string ToDecryption(this string value)
        {
            if (string.IsNullOrEmpty(value))
            {
                return(string.Empty);
            }

            var e          = new RijndaelEnhanced(passPhrase, initVector);
            var removeSalt = value.Replace(salt, "");

            return(e.Decrypt(removeSalt));
        }
Example #4
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);
        }
Example #5
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;
        }
Example #6
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));
        }