SenseNet.ContentRepository.CryptoApi.Crypt C# (CSharp) Method

Crypt() public static method

public static Crypt ( string input, string passphrase, string IVString ) : string
input string
passphrase string
IVString string
return string
        public static string Crypt(string input, string passphrase, string IVString)
        {
            byte[] inputbytes = Encoding.Default.GetBytes(input);

            var provider = new RijndaelManaged();
            var hashMD5 = new MD5CryptoServiceProvider();
            byte[] key = hashMD5.ComputeHash(System.Text.ASCIIEncoding.ASCII.GetBytes(passphrase));
            byte[] IV = hashMD5.ComputeHash(System.Text.ASCIIEncoding.ASCII.GetBytes(IVString));

            provider.Mode = CMode;

            var ms = new MemoryStream();
            var cs = new CryptoStream(ms, provider.CreateEncryptor(key, IV),
                CryptoStreamMode.Write);
            cs.Write(inputbytes, 0, inputbytes.Length);
            cs.FlushFinalBlock();


            byte[] bytes = ms.ToArray();

            string base64 = HttpServerUtility.UrlTokenEncode(bytes); // Convert.ToBase64String(bytes);
            return base64;
        }
    }