mirror of
https://github.com/tgstation/tgstation-server.git
synced 2026-08-26 22:48:20 +01:00
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
35 lines
950 B
C#
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;
|
|
}
|
|
}
|
|
}
|
|
}
|