diff --git a/GreenshotPlugin/Core/EncryptionHelper.cs b/GreenshotPlugin/Core/EncryptionHelper.cs new file mode 100644 index 000000000..4f1c4cc92 --- /dev/null +++ b/GreenshotPlugin/Core/EncryptionHelper.cs @@ -0,0 +1,56 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Security.Cryptography; +using System.IO; + +namespace GreenshotPlugin.Core { + public static class EncryptionHelper { + private const string RGBIV = "dlgjowejgogkklwj"; + private const string KEY = "lsjvkwhvwujkagfauguwcsjgu2wueuff"; + + /// + /// A simply rijndael aes encryption, can be used to store passwords + /// + /// the string to call upon + /// an encryped string in base64 form + public static string Encrypt(this string ClearText) { + byte[] clearTextBytes = Encoding.UTF8.GetBytes(ClearText); + + SymmetricAlgorithm rijn = SymmetricAlgorithm.Create(); + + using (MemoryStream ms = new MemoryStream()) { + byte[] rgbIV = Encoding.ASCII.GetBytes(RGBIV); + byte[] key = Encoding.ASCII.GetBytes(KEY); + CryptoStream cs = new CryptoStream(ms, rijn.CreateEncryptor(key, rgbIV), CryptoStreamMode.Write); + + cs.Write(clearTextBytes, 0, clearTextBytes.Length); + return Convert.ToBase64String(ms.ToArray()); + } + } + + /// + /// A simply rijndael aes decryption, can be used to store passwords + /// + /// a base64 encoded rijndael encrypted string + /// Decrypeted text + public static string Decrypt(this string EncryptedText) { + byte[] encryptedTextBytes = Convert.FromBase64String(EncryptedText); + + using (MemoryStream ms = new MemoryStream()) { + SymmetricAlgorithm rijn = SymmetricAlgorithm.Create(); + + + byte[] rgbIV = Encoding.ASCII.GetBytes(RGBIV); + byte[] key = Encoding.ASCII.GetBytes(KEY); + + CryptoStream cs = new CryptoStream(ms, rijn.CreateDecryptor(key, rgbIV), + CryptoStreamMode.Write); + + cs.Write(encryptedTextBytes, 0, encryptedTextBytes.Length); + + return Encoding.UTF8.GetString(ms.ToArray()); + } + } + } +} diff --git a/GreenshotPlugin/GreenshotPlugin.csproj b/GreenshotPlugin/GreenshotPlugin.csproj index 435b4703e..ae71e0ea6 100644 --- a/GreenshotPlugin/GreenshotPlugin.csproj +++ b/GreenshotPlugin/GreenshotPlugin.csproj @@ -197,6 +197,7 @@ +