public Base64 Encrypt(string userInput)
        {
            string sanitisedUserInput = userInput.Replace(";", String.Empty).Replace("=", String.Empty);
            string padded             = prepend + sanitisedUserInput + append;

            return(cipher.Encrypt(key, padded, iv));
        }
Example #2
0
        public EncryptedData GetEncryptedCookie()
        {
            string[] lines = File.ReadAllLines(SessionValues);
            string   line  = lines[random.Next(lines.Length)];

            decoded = new Base64(line).Decode();
            string iv = helper.GenerateKey().ToString();

            return(new EncryptedData(cipherCBC.Encrypt(key, decoded, iv), iv));
        }
Example #3
0
        public Tuple <Base64, string> EncryptWithRandomPadding(string data)
        {
            string plainText = PadData(data);

            if (random.Next(2) == 1)
            {
                return(new Tuple <Base64, string>(cipherCBC.Encrypt(plainText), "CBC"));
            }
            else
            {
                return(new Tuple <Base64, string>(cipherECB.Encrypt(plainText), "EBC"));
            }
        }
        public void EncryptAndDecryptCBC()
        {
            Random r = new Random();

            byte[] bytes = new byte[r.Next(100)];
            r.NextBytes(bytes);

            string data = new Bytes(bytes).ToString();
            string key  = "YELLOW SUBMARINE";

            string iv = new String('\0', blockSize);

            AESCipherCBC aes       = new AESCipherCBC();
            Base64       encrypted = aes.Encrypt(key, data, iv);
            string       decrypted = aes.Decrypt(key, encrypted, iv);

            Assert.AreEqual(data, decrypted);
        }