cryptStream.FlushFinalBlock();
public string RamziKonToString(string inputText) { //declare a new encoder UTF8Encoding UTF8Encoder = new UTF8Encoding(); //get byte representation of string byte[] inputBytes = UTF8Encoder.GetBytes(inputText); //////////////////////////////////////////////////////////////////////// //get the correct transform ICryptoTransform transform = SA.CreateEncryptor(); SA.Mode = CipherMode.CBC; SA.Padding = PaddingMode.PKCS7; SA.Key = kelid; SA.IV = iV; //memory stream for output MemoryStream memStream = new MemoryStream(); //setup the cryption - output written to memstream CryptoStream cryptStream = new CryptoStream(memStream, transform, CryptoStreamMode.Write); //write data to cryption engine cryptStream.Write(inputBytes, 0, inputBytes.Length); //we are finished cryptStream.FlushFinalBlock(); //get result byte[] output = memStream.ToArray(); //finished with engine, so close the stream cryptStream.Close(); /////////////////////////////////////////////////////////////////////////////// //convert back to a string return Convert.ToBase64String(output); }
public string KashfeRamz(string inputText) { //declare a new encoder UTF8Encoding UTF8Encoder = new UTF8Encoding(); //get byte representation of string byte[] inputBytes = Convert.FromBase64String(inputText); /////////////////////////////////////////////////////////// //get the correct transform ICryptoTransform transform = SA.CreateDecryptor(); SA.Padding = PaddingMode.PKCS7; SA.Key = kelid; SA.IV = iV; SA.Mode = CipherMode.CBC; //memory stream for output MemoryStream memStream = new MemoryStream(); //setup the cryption - output written to memstream CryptoStream cryptStream = new CryptoStream(memStream, transform, CryptoStreamMode.Write); //write data to cryption engine using (var sw = new StreamWriter(cryptStream)) { sw.Write(inputBytes); cryptStream.FlushFinalBlock(); } //cryptStream.Write(inputBytes, 0, inputBytes.Length); //we are finished //get result byte[] output = memStream.ToArray(); //finished with engine, so close the stream cryptStream.Close(); ///////////////////////////////////////////////////////////////// //convert back to a string return UTF8Encoder.GetString(output); }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)