Files
tgstation-server/TGServiceInterface/Helpers.cs
T
Cyberboss d88a422125 Control Panel login screen improvements
Allows saving of remote access password

Remote access button selected by default if used last

Tabbing through the page now goes in a sane fashion
2017-09-29 12:57:22 -04:00

35 lines
950 B
C#

using System;
using System.Security.Cryptography;
using System.Text;
namespace TGServiceInterface
{
public static class Helpers
{
public static string EncryptData(string data, out string sentropy)
{
// Generate additional entropy (will be used as the Initialization vector)
byte[] entropy = new byte[20];
using (var rng = new RNGCryptoServiceProvider())
rng.GetBytes(entropy);
byte[] ciphertext = ProtectedData.Protect(Encoding.UTF8.GetBytes(data), entropy, DataProtectionScope.CurrentUser);
sentropy = Convert.ToBase64String(entropy, 0, entropy.Length);
return Convert.ToBase64String(ciphertext, 0, ciphertext.Length);
}
public static string DecryptData(string data, string entropy)
{
try
{
return Encoding.UTF8.GetString(ProtectedData.Unprotect(Convert.FromBase64String(data), Convert.FromBase64String(entropy), DataProtectionScope.CurrentUser));
}
catch
{
return null;
}
}
}
}