public string Hash(string value, IEncryptionProfile encryptionProfile) { var byteValue = encryptionProfile.Encoding.GetBytes(value); using var hashAlgorithm = HashAlgorithm .Create(GetHashAlgorithmName(encryptionProfile.HashAlgorithmType).Name); return(Convert.ToBase64String( hashAlgorithm.ComputeHash( SaltKey(encryptionProfile.Salt, byteValue).ToArray()))); }
public string Encrypt(string value, IEncryptionProfile encryptionProfile) { byte[] result = null; InvokeSymmetricAlgorithm(symmetricAlgorithm => { var encryptor = symmetricAlgorithm.CreateEncryptor( encryptionProfile.Key.ToArray(), encryptionProfile.InitialVector.ToArray()); using var memoryStream = new MemoryStream(); using (var cryptoStream = new CryptoStream(memoryStream, encryptor, CryptoStreamMode.Write)) using (var streamWriter = new StreamWriter(cryptoStream)) streamWriter.Write(value); result = memoryStream.ToArray(); }, encryptionProfile.SymmetricAlgorithmName); return(Convert.ToBase64String(result)); }
public string Decrypt(string encryptedValue, IEncryptionProfile encryptionProfile) { var value = Convert.FromBase64String(encryptedValue); var result = string.Empty; InvokeSymmetricAlgorithm(symmetricAlgorithm => { var encryptor = symmetricAlgorithm.CreateDecryptor( encryptionProfile.Key.ToArray(), encryptionProfile.InitialVector.ToArray()); using var memoryStream = new MemoryStream(value); using var cryptoStream = new CryptoStream(memoryStream, encryptor, CryptoStreamMode.Read); using var streamReader = new StreamReader(cryptoStream); result = streamReader.ReadToEnd(); }, encryptionProfile.SymmetricAlgorithmName); return(result); }
bool IReadOnlyDictionary <EncryptionClassification, IEncryptionProfile> .TryGetValue(EncryptionClassification key, out IEncryptionProfile value) { return(dictionary.TryGetValue(key, out value)); }