public static BaseEncryptor GetEncryptor(Encryptor encryptor) { BaseEncryptor cryptoProvider = null; if (encryptor == Encryptor.Aes) { if (rijndaelEncryptor == null) { rijndaelEncryptor = new RijndaelEncryptor(); } cryptoProvider = rijndaelEncryptor; } if (encryptor == Encryptor.Des) { if (dataEncryptor == null) { dataEncryptor = new DataEncryptor(); } cryptoProvider = dataEncryptor; } if (encryptor == Encryptor.Hash) { if (hashEncryptor == null) { hashEncryptor = new HashEncryptor(); } cryptoProvider = hashEncryptor; } return(cryptoProvider); }
public void ValidateTest() { string message = "XphteR"; HashEncryptor encryptor = new HashEncryptor(Encoding.UTF8, new SHA256Managed()); Assert.IsTrue(encryptor.Validate(message, encryptor.Encrypt(message))); }
public async Task <IdentityResult> CreateAsync(User user, CancellationToken cancellationToken) { user.SecurityStamp = Guid.NewGuid().ToString().ToLower().Replace("-", ""); user.PasswordHash = HashEncryptor.HmacSha1(user.SecurityStamp, user.PasswordHash); await db.Users.AddAsync(user); await db.SaveChangesAsync(); return(IdentityResult.Success); }
public string HashPassword(User user, string password) { return(HashEncryptor.HmacSha1(user.SecurityStamp, password)); }