Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.IO;
- using System.Security.Cryptography;
- using System.Text;
- public class CR
- {
- private const string K = "667912";
- private const string I = "1L1SA61493DRV53Z";
- private const string SA = "1313Rf99";
- public static string DS(string EncryptedString)
- {
- if (string.IsNullOrEmpty(EncryptedString))
- {
- return string.Empty;
- }
- return RD(EncryptedString, "667912", "1313Rf99", 3, "1L1SA61493DRV53Z", 256);
- }
- public static string ES(string PlainString)
- {
- if (string.IsNullOrEmpty(PlainString))
- {
- return string.Empty;
- }
- return RE(PlainString, "667912", "1313Rf99", 3, "1L1SA61493DRV53Z", 256);
- }
- private static string RE(string plainText, string passPhrase, string saltValue, int passwordIterations, string initVector, int keySize)
- {
- //Discarded unreachable code: IL_00b9
- byte[] bytes = Encoding.ASCII.GetBytes(initVector);
- byte[] bytes2 = Encoding.ASCII.GetBytes(saltValue);
- byte[] bytes3 = Encoding.ASCII.GetBytes(plainText);
- Rfc2898DeriveBytes rfc2898DeriveBytes = new Rfc2898DeriveBytes(passPhrase, bytes2, passwordIterations);
- byte[] bytes4 = rfc2898DeriveBytes.GetBytes(checked((int)Math.Round((double)keySize / 8.0)));
- AesCryptoServiceProvider aesCryptoServiceProvider = new AesCryptoServiceProvider();
- aesCryptoServiceProvider.Mode = CipherMode.CBC;
- ICryptoTransform transform = aesCryptoServiceProvider.CreateEncryptor(bytes4, bytes);
- using (MemoryStream memoryStream = new MemoryStream())
- {
- using (CryptoStream cryptoStream = new CryptoStream(memoryStream, transform, CryptoStreamMode.Write))
- {
- cryptoStream.Write(bytes3, 0, bytes3.Length);
- cryptoStream.FlushFinalBlock();
- byte[] inArray = memoryStream.ToArray();
- memoryStream.Close();
- cryptoStream.Close();
- return Convert.ToBase64String(inArray);
- }
- }
- }
- private static string RD(string cipherText, string passPhrase, string saltValue, int passwordIterations, string initVector, int keySize)
- {
- byte[] bytes = Encoding.ASCII.GetBytes(initVector);
- byte[] bytes2 = Encoding.ASCII.GetBytes(saltValue);
- byte[] array = Convert.FromBase64String(cipherText);
- Rfc2898DeriveBytes rfc2898DeriveBytes = new Rfc2898DeriveBytes(passPhrase, bytes2, passwordIterations);
- checked
- {
- byte[] bytes3 = rfc2898DeriveBytes.GetBytes((int)Math.Round((double)keySize / 8.0));
- AesCryptoServiceProvider aesCryptoServiceProvider = new AesCryptoServiceProvider();
- aesCryptoServiceProvider.Mode = CipherMode.CBC;
- ICryptoTransform transform = aesCryptoServiceProvider.CreateDecryptor(bytes3, bytes);
- MemoryStream memoryStream = new MemoryStream(array);
- CryptoStream cryptoStream = new CryptoStream(memoryStream, transform, CryptoStreamMode.Read);
- byte[] array2 = new byte[array.Length + 1];
- int count = cryptoStream.Read(array2, 0, array2.Length);
- memoryStream.Close();
- cryptoStream.Close();
- return Encoding.ASCII.GetString(array2, 0, count);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment