53 lines
1.6 KiB
C#
53 lines
1.6 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace SetAlertTemplate
|
|
{
|
|
public class CredentialsCryptographer
|
|
{
|
|
private const string KEY = "{603DEF77-5D07-46B4-8971-9C459841CE2C}";
|
|
|
|
public static string Encrypt(string str)
|
|
{
|
|
try
|
|
{
|
|
if (string.IsNullOrEmpty(str))
|
|
{
|
|
return string.Empty;
|
|
}
|
|
var cryptographer = new SymCryptography(SymCryptography.ServiceProviderEnum.Rijndael);
|
|
cryptographer.Key = KEY;
|
|
byte[] encrypted = cryptographer.Encrypt(Encoding.UTF8.GetBytes(str));
|
|
return Convert.ToBase64String(encrypted);
|
|
}
|
|
catch (Exception x)
|
|
{
|
|
Program.log("Error occured during encrypt. Empty string will be returned: {0}", x.Message);
|
|
return string.Empty;
|
|
}
|
|
}
|
|
|
|
public static string Decrypt(string str)
|
|
{
|
|
try
|
|
{
|
|
if (string.IsNullOrEmpty(str))
|
|
{
|
|
return string.Empty;
|
|
}
|
|
var cryptographer = new SymCryptography(SymCryptography.ServiceProviderEnum.Rijndael);
|
|
cryptographer.Key = KEY;
|
|
return cryptographer.Decrypt(Convert.FromBase64String(str));
|
|
}
|
|
catch (Exception x)
|
|
{
|
|
Program.log("Error occured during decrypt. Empty string will be returned: {0}", x.Message);
|
|
return string.Empty;
|
|
}
|
|
}
|
|
}
|
|
}
|