public int EncryptBuffW(string InDec_buffer, out string OutEnc_buffer, out int OutEnc_bSize) { OutEnc_buffer = ""; OutEnc_bSize = 0; string OutData = ""; CryptoStream encStream = null; MemoryStream fin = null; MemoryStream fout = new MemoryStream(); try { try { byte[] data = Encoding.Unicode.GetBytes(InDec_buffer); //Create the file streams to handle the input and output files. fin = new MemoryStream(data); //Create variables to help with read and write. byte[] bin = new byte[bufLen]; //This is intermediate storage for the encryption. long rdlen = 0; //This is the total number of bytes written. long totlen = fin.Length; //This is the total length of the input file. int len; //This is the number of bytes to be written at a time. RijndaelManaged rijn = new RijndaelManaged(); rijn.Mode = CipherMode.CBC; rijn.KeySize = 256; rijn.BlockSize = 128; rijn.Padding = PaddingMode.PKCS7; encStream = new CryptoStream(fout, rijn.CreateEncryptor(cryptoKey, cryptoIV), CryptoStreamMode.Write); //Read from the input file, then encrypt and write to the output file. while (true) { len = fin.Read(bin, 0, bufLen); if (len == 0) break; encStream.Write(bin, 0, len); rdlen += len; } encStream.FlushFinalBlock(); OutEnc_buffer = Encoding.Unicode.GetString(fout.ToArray()); /* StreamWriter wr = new StreamWriter("c:\\fff.txt", true, Encoding.Unicode); wr.Write(OutEnc_buffer); wr.Close();*/ } catch (Exception e) { if (logPermission) { SetErrLogFileName("EncryptBuffW:" + " Exception Details: " + e.Message); } return 1; } finally { if (encStream != null) encStream.Close(); if (fout != null) fout.Close(); if (fin != null) fin.Close(); } } catch (Exception ee) { if (logPermission) { SetErrLogFileName("EncryptBuffW:" + " Exception Details: " + ee.Message); } return 1; } OutEnc_bSize = OutEnc_buffer.Length; return 0; } public int DecryptBuffW(string InEnc_buffer, int InEnc_bSize, out string OutDec_buffer) { OutDec_buffer = ""; InEnc_bSize = 0; string OutData = ""; CryptoStream encStream = null; MemoryStream fin = null; MemoryStream fout = new MemoryStream(); try { try { byte[] data = Encoding.Unicode.GetBytes(InEnc_buffer); //Create the file streams to handle the input and output files. fin = new MemoryStream(data); //Create variables to help with read and write. byte[] bin = new byte[bufLen]; //This is intermediate storage for the encryption. long rdlen = 0; //This is the total number of bytes written. long totlen = fin.Length; //This is the total length of the input file. int len; //This is the number of bytes to be written at a time. RijndaelManaged rijn = new RijndaelManaged(); rijn.Mode = CipherMode.CBC; rijn.KeySize = 256; rijn.BlockSize = 128; rijn.Padding = PaddingMode.PKCS7; encStream = new CryptoStream(fout, rijn.CreateDecryptor(cryptoKey, cryptoIV), CryptoStreamMode.Write); //Read from the input file, then encrypt and write to the output file. while (true) { len = fin.Read(bin, 0, bufLen); if (len == 0) break; encStream.Write(bin, 0, len); rdlen += len; } encStream.FlushFinalBlock(); OutDec_buffer = Encoding.Unicode.GetString(fout.ToArray()); /*StreamWriter wr = new StreamWriter("c:\\fff.txt",true,Encoding.Default); wr.Write(OutEnc_buffer); wr.Close();*/ } catch (Exception e) { if (logPermission) { SetErrLogFileName("DecryptBuffW:" + " Exception Details: " + e.Message); } return 1; } finally { if (encStream != null) encStream.Close(); if (fout != null) fout.Close(); if (fin != null) fin.Close(); } } catch (Exception ee) { if (logPermission) { SetErrLogFileName("DecryptBuffW:" + " Exception Details: " + ee.Message); } return 1; } InEnc_bSize = OutDec_buffer.Length; return 0; }
OutEnc_buffer = Encoding.Unicode.GetString(fout.ToArray());
OutEnc_buffer = Convert.ToBase64String(fout.ToArray());
byte[] data = Convert.FromBase64String(InEnc_buffer);
byte[] data = Encoding.Unicode.GetBytes(InEnc_buffer);
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)