Created
April 2, 2018 16:37
-
-
Save configureappio/efc0bc4b4db24b749c4424c90f33078f to your computer and use it in GitHub Desktop.
Example of decrypting a dictionary with a hashed key
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class SettingsDecryptor : ISettingsDecrypt | |
{ | |
private readonly ICryptoAlgorithm _crypto; | |
public SettingsDecryptor(ICryptoAlgorithm crypto) | |
{ | |
_crypto = crypto ?? throw new ArgumentNullException(nameof(crypto)); | |
} | |
public string Decrypt(string key, IDictionary<string, string> keyValues) | |
{ | |
var hashedKey = _crypto.HashKey(key); | |
var value = keyValues[hashedKey]; | |
return DecryptValue(value); | |
} | |
private string DecryptValue(string encodedString) | |
{ | |
return _crypto.Decrypt(encodedString); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment