123123
This commit is contained in:
@@ -6,6 +6,7 @@ namespace ZelWiki.Security
|
||||
public static class Helpers
|
||||
{
|
||||
private static string? _machineKey;
|
||||
|
||||
public static string MachineKey
|
||||
=> _machineKey ??= Sha1(Environment.MachineName);
|
||||
|
||||
@@ -35,22 +36,23 @@ namespace ZelWiki.Security
|
||||
public static string Sha256(string value)
|
||||
{
|
||||
var hash = new StringBuilder();
|
||||
byte[] crypto = SHA256.HashData(Encoding.UTF8.GetBytes(value));
|
||||
var crypto = SHA256.HashData(Encoding.UTF8.GetBytes(value));
|
||||
foreach (byte theByte in crypto)
|
||||
{
|
||||
hash.Append(theByte.ToString("x2"));
|
||||
}
|
||||
|
||||
return hash.ToString();
|
||||
}
|
||||
|
||||
public static string EncryptString(string key, string plainText)
|
||||
{
|
||||
using var aes = Aes.Create();
|
||||
byte[] iv = new byte[16];
|
||||
byte[] keyBytes = SHA256.HashData(Encoding.Unicode.GetBytes(key));
|
||||
byte[] vector = (byte[])keyBytes.Clone();
|
||||
var iv = new byte[16];
|
||||
var keyBytes = SHA256.HashData(Encoding.Unicode.GetBytes(key));
|
||||
var vector = (byte[])keyBytes.Clone();
|
||||
|
||||
for (int i = 0; i < 16; i++)
|
||||
for (var i = 0; i < 16; i++)
|
||||
{
|
||||
iv[i] = vector[i];
|
||||
}
|
||||
@@ -72,14 +74,14 @@ namespace ZelWiki.Security
|
||||
|
||||
public static string DecryptString(string key, string cipherText)
|
||||
{
|
||||
byte[] buffer = Convert.FromBase64String(cipherText);
|
||||
var buffer = Convert.FromBase64String(cipherText);
|
||||
|
||||
using var aes = Aes.Create();
|
||||
byte[] iv = new byte[16];
|
||||
byte[] keyBytes = SHA256.HashData(Encoding.Unicode.GetBytes(key));
|
||||
byte[] vector = (byte[])keyBytes.Clone();
|
||||
var iv = new byte[16];
|
||||
var keyBytes = SHA256.HashData(Encoding.Unicode.GetBytes(key));
|
||||
var vector = (byte[])keyBytes.Clone();
|
||||
|
||||
for (int i = 0; i < 16; i++)
|
||||
for (var i = 0; i < 16; i++)
|
||||
{
|
||||
iv[i] = vector[i];
|
||||
}
|
||||
@@ -95,4 +97,4 @@ namespace ZelWiki.Security
|
||||
return streamReader.ReadToEnd();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user