Skip to content

Instantly share code, notes, and snippets.

@goors
Last active May 24, 2024 22:55
Show Gist options
  • Save goors/0ba3b0d2b08b8b22d351b13d3288ade5 to your computer and use it in GitHub Desktop.
Save goors/0ba3b0d2b08b8b22d351b13d3288ade5 to your computer and use it in GitHub Desktop.
public string HashSecret(string secret) {
using var sha256 = SHA256.Create();
// Compute hash of the password
var hashBytes = sha256.ComputeHash(Encoding.UTF8.GetBytes(secret));
// Convert byte array to a hexadecimal string
var builder = new StringBuilder();
foreach (var t in hashBytes) {
builder.Append(t.ToString("x2"));
}
return builder.ToString();
}
@goors
Copy link
Author

goors commented May 24, 2024

Test hash: 473287f8298dba7163a897908958f7c0eae733e25d2e027992ea2edc9bed2fa8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment