mirror of
https://github.com/greenshot/greenshot
synced 2025-07-15 01:23:47 -07:00
Added an EncryptionHelper, can be used to store passwords.
git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@1771 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4
This commit is contained in:
parent
2b8b3c7a62
commit
84947c8b6e
2 changed files with 57 additions and 0 deletions
56
GreenshotPlugin/Core/EncryptionHelper.cs
Normal file
56
GreenshotPlugin/Core/EncryptionHelper.cs
Normal file
|
@ -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";
|
||||
|
||||
/// <summary>
|
||||
/// A simply rijndael aes encryption, can be used to store passwords
|
||||
/// </summary>
|
||||
/// <param name="ClearText">the string to call upon</param>
|
||||
/// <returns>an encryped string in base64 form</returns>
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A simply rijndael aes decryption, can be used to store passwords
|
||||
/// </summary>
|
||||
/// <param name="EncryptedText">a base64 encoded rijndael encrypted string</param>
|
||||
/// <returns>Decrypeted text</returns>
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -197,6 +197,7 @@
|
|||
<Compile Include="Core\CacheHelper.cs" />
|
||||
<Compile Include="Core\CoreConfiguration.cs" />
|
||||
<Compile Include="Core\CredentialsHelper.cs" />
|
||||
<Compile Include="Core\EncryptionHelper.cs" />
|
||||
<Compile Include="Core\InterfaceUtils.cs" />
|
||||
<Compile Include="Core\DisplayKeyAttribute.cs" />
|
||||
<Compile Include="Core\EmailConfigHelper.cs" />
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue