From 9d19c0fca9683efb200a08652ce870cd011b9c7c Mon Sep 17 00:00:00 2001 From: Kim Date: Thu, 16 Feb 2023 14:42:13 +0100 Subject: [PATCH] added salt to password, it's edible now --- csharp/app/Backend/Utils/Crypto.cs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 csharp/app/Backend/Utils/Crypto.cs diff --git a/csharp/app/Backend/Utils/Crypto.cs b/csharp/app/Backend/Utils/Crypto.cs new file mode 100644 index 000000000..f2a236367 --- /dev/null +++ b/csharp/app/Backend/Utils/Crypto.cs @@ -0,0 +1,20 @@ +using System.Security.Cryptography; + +namespace Backend.Utils; + +public class Crypto +{ + public String ComputeHash(Byte[] bytesToHash, Byte[] salt) + { + var byteResult = new Rfc2898DeriveBytes(bytesToHash, salt, 10000); + return Convert.ToBase64String(byteResult.GetBytes(24)); + } + + public string GenerateSalt() + { + var bytes = new byte[128 / 8]; + var rng = new RNGCryptoServiceProvider(); + rng.GetBytes(bytes); + return Convert.ToBase64String(bytes); + } +} \ No newline at end of file