Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Text;
- using System.IO;
- using System.Security.Cryptography;
- namespace ProbeConnect
- {
- class Crypter
- {
- private const string EncPassword = "bavEccyc%sabHij$onLoa$$$wAwC/oachH(iQuivC)ankUng";
- public static String Encrypt(String str)
- {
- const string password = EncPassword;
- var pdb = new PasswordDeriveBytes(password,
- new byte[] {0x49, 0x76, 0x61, 0x6e, 0x20, 0x4d,
- 0x65, 0x64, 0x76, 0x65, 0x64, 0x65, 0x76});
- var key = pdb.GetBytes(16);
- var iv = pdb.GetBytes(8);
- var des = new CTripleDes(key, iv);
- try
- {
- return des.Encrypt(str);
- }
- catch
- {
- return "error encrypting content";
- }
- }
- public static String Decrypt(String str)
- {
- const string password = EncPassword;
- var pdb = new PasswordDeriveBytes(password,
- new byte[] {0x49, 0x76, 0x61, 0x6e, 0x20, 0x4d,
- 0x65, 0x64, 0x76, 0x65, 0x64, 0x65, 0x76});
- byte[] key = pdb.GetBytes(16);
- byte[] iv = pdb.GetBytes(8);
- CTripleDes des = new CTripleDes(key, iv);
- try
- {
- return des.Decrypt(str);
- }
- catch
- {
- return "error decrypting content";
- }
- }
- #region Cryptography alogrithm
- class CTripleDes
- {
- private TripleDESCryptoServiceProvider m_des =
- new TripleDESCryptoServiceProvider();
- private UTF8Encoding m_utf8 = new UTF8Encoding();
- private byte[] m_key;
- private byte[] m_iv;
- public CTripleDes(byte[] key, byte[] iv)
- {
- this.m_key = key;
- this.m_iv = iv;
- }
- public byte[] Encrypt(byte[] input)
- {
- return Transform(input,
- m_des.CreateEncryptor(m_key, m_iv));
- }
- public byte[] Decrypt(byte[] input)
- {
- return Transform(input,
- m_des.CreateDecryptor(m_key, m_iv));
- }
- public string Encrypt(string text)
- {
- byte[] input = m_utf8.GetBytes(text);
- byte[] output = Transform(input,
- m_des.CreateEncryptor(m_key, m_iv));
- return Convert.ToBase64String(output);
- }
- public string Decrypt(string text)
- {
- byte[] input = Convert.FromBase64String(text);
- byte[] output = Transform(input,
- m_des.CreateDecryptor(m_key, m_iv));
- return m_utf8.GetString(output);
- }
- private byte[] Transform(byte[] input,
- ICryptoTransform CryptoTransform)
- {
- MemoryStream memStream = new MemoryStream();
- CryptoStream cryptStream = new CryptoStream(memStream,
- CryptoTransform, CryptoStreamMode.Write);
- cryptStream.Write(input, 0, input.Length);
- cryptStream.FlushFinalBlock();
- memStream.Position = 0;
- byte[] result = memStream.ToArray();
- memStream.Close();
- cryptStream.Close();
- return result;
- }
- }
- #endregion
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement