using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Security.Cryptography; using System.Text; using System.Threading.Tasks; namespace PEP_Tool { internal class Crypto { public static byte[] GetHashKey(string hashKey, string Salt = "D99CFBD250C45D34B954C74E2054A282") { // Initialize UTF8Encoding encoder = new UTF8Encoding(); // Get the salt string salt = !string.IsNullOrEmpty(Salt) ? Salt : "I am a nice little salt"; byte[] saltBytes = encoder.GetBytes(salt); // Setup the hasher Rfc2898DeriveBytes rfc = new Rfc2898DeriveBytes(hashKey, saltBytes); // Return the key return rfc.GetBytes(16); } public static string Decrypt(byte[] key, string encryptedString) { // Initialize AesManaged decryptor = new AesManaged(); byte[] encryptedData = Convert.FromBase64String(encryptedString); // Set the key decryptor.Key = key; decryptor.IV = key; // create a memory stream using (MemoryStream decryptionStream = new MemoryStream()) { // Create the crypto stream using (CryptoStream decrypt = new CryptoStream(decryptionStream, decryptor.CreateDecryptor(), CryptoStreamMode.Write)) { // Encrypt decrypt.Write(encryptedData, 0, encryptedData.Length); decrypt.Flush(); decrypt.Close(); // Return the unencrypted data byte[] decryptedData = decryptionStream.ToArray(); return UTF8Encoding.UTF8.GetString(decryptedData, 0, decryptedData.Length); } } } } }