/ Published in: C#
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
public string EncrypToText(string textToEncrypt) { try { return Convert.ToBase64String(this.EncryptToBinary(textToEncrypt)); } catch (Exception ex) { } } public byte[] EncryptToBinary(string textToEncrypt) { try { byte[] input = this.utf8.GetBytes(textToEncrypt); return this.Transform(input, this.cryptdes.CreateEncryptor(this.key, this.iv)); } catch (Exception ex) { } } private byte[] Transform(byte[] input, ICryptoTransform CryptoTransform) { // create the necessary streams // transform the bytes as requested cryptStream.Write(input, 0, input.Length); cryptStream.FlushFinalBlock(); // Read the memory stream and convert it back into byte array memStream.Position = 0; byte[] result = memStream.ToArray(); // Clean up memStream.Close(); cryptStream.Close(); return result; }