Example #1
0
        public void TestEncryptStringToBase64()
        {
            var encryptor = new TripleDes();
            string raw = "Đây là Unicode string", key = "password", salt = "this_is_salt";
            string encrypted; string decrypted;

            // without salt
            encrypted = encryptor.EncryptToBase64(raw, key);
            Assert.NotNull(encrypted);
            decrypted = encryptor.DecryptFromBase64ToString(encrypted, key);
            Assert.NotNull(decrypted);
            Assert.Equal(raw, decrypted);

            // with salt
            encrypted = encryptor.EncryptToBase64(raw, key, salt);
            Assert.NotNull(encrypted);
            decrypted = encryptor.DecryptFromBase64ToString(encrypted, key);
            Assert.NotNull(decrypted);
            Assert.Equal(raw, decrypted);
        }