Choosing the right hash algorithm for password storage
Posted by JaneDoe on Sep 12, 2025
Discussion about Argon2 vs PBKDF2 vs BCrypt in .NET 8.
Read more »Posted by JaneDoe on Sep 12, 2025
Discussion about Argon2 vs PBKDF2 vs BCrypt in .NET 8.
Read more »Posted by CryptoGuru on Sep 10, 2025
Implementation details using System.Security.Cryptography.
Read more »Explore how RSA keys are generated, stored, and used in .NET 8.
Read article »Best practices for generating cryptographically strong randomness.
Read article »using System.Security.Cryptography;
public static class AesHelper
{
public static (byte[] Cipher, byte[] IV) Encrypt(byte[] plain, byte[] key)
{
using var aes = Aes.Create();
aes.Key = key;
aes.GenerateIV();
using var encryptor = aes.CreateEncryptor();
var cipher = encryptor.TransformFinalBlock(plain,0,plain.Length);
return (cipher, aes.IV);
}
public static byte[] Decrypt(byte[] cipher, byte[] key, byte[] iv)
{
using var aes = Aes.Create();
aes.Key = key;
aes.IV = iv;
using var decryptor = aes.CreateDecryptor();
return decryptor.TransformFinalBlock(cipher,0,cipher.Length);
}
}
using System.Security.Cryptography;
public static string HashPassword(string password, byte[] salt, int iterations = 100_000)
{
var pbkdf2 = new Rfc2898DeriveBytes(password, salt, iterations, HashAlgorithmName.SHA256);
var hash = pbkdf2.GetBytes(32);
return Convert.ToBase64String(hash);
}