| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- using System;
- using System.IO;
- using System.Security.Cryptography;
- using System.Text;
- namespace LauncherIcarus.Daemon
- {
- public static class EncryptionHelper
- {
- private const string Password = "N1PEUPQX";
- private static Rfc2898DeriveBytes Rfc2898DeriveBytes { get; } = new Rfc2898DeriveBytes(Password, new byte[]
- {
- 73,
- 118,
- 97,
- 110,
- 32,
- 77,
- 101,
- 100,
- 118,
- 101,
- 100,
- 101,
- 118
- });
- public static string Encrypt(string clearText)
- {
- var bytes = Encoding.Unicode.GetBytes(clearText);
- using (var aes = Aes.Create())
- {
- aes.Key = Rfc2898DeriveBytes.GetBytes(32);
- aes.IV = Rfc2898DeriveBytes.GetBytes(16);
- using (var memoryStream = new MemoryStream())
- {
- using (var cryptoStream =
- new CryptoStream(memoryStream, aes.CreateEncryptor(), CryptoStreamMode.Write))
- {
- cryptoStream.Write(bytes, 0, bytes.Length);
- cryptoStream.Close();
- }
- clearText = Convert.ToBase64String(memoryStream.ToArray());
- }
- }
- return clearText;
- }
- public static string Decrypt(string cipherText)
- {
- cipherText = cipherText.Replace(" ", "+");
- var buffer = Convert.FromBase64String(cipherText);
- using (var aes = Aes.Create())
- {
- aes.Key = Rfc2898DeriveBytes.GetBytes(32);
- aes.IV = Rfc2898DeriveBytes.GetBytes(16);
- using (var memoryStream = new MemoryStream())
- {
- using (var cryptoStream =
- new CryptoStream(memoryStream, aes.CreateDecryptor(), CryptoStreamMode.Write))
- {
- cryptoStream.Write(buffer, 0, buffer.Length);
- cryptoStream.Close();
- }
- cipherText = Encoding.Unicode.GetString(memoryStream.ToArray());
- }
- }
- return cipherText;
- }
- }
- }
|