// getting the key | |
private KeyClient KeyClient => new KeyClient( | |
vaultUri: new Uri(_configuration["KeyVaultUri"]), | |
credential: _getCredentialService.GetKeyVaultCredentials()); | |
public async Task<KeyVaultKey> GetEncryptionKey() | |
{ | |
var keyResponse = await KeyClient.GetKeyAsync("encryption-key"); | |
return keyResponse.Value; | |
} | |
// usage | |
public async Task<string> Encrypt(string rawValue) | |
{ | |
var encryptionKey = await _keyVaultService.GetEncryptionKey(); | |
var cryptoClient = new CryptographyClient(encryptionKey.Id, _getCredentialService.GetKeyVaultCredentials()); | |
var byteData = Encoding.Unicode.GetBytes(rawValue); | |
var encryptResult = await cryptoClient.EncryptAsync(EncryptionAlgorithm.RsaOaep, byteData); | |
return Convert.ToBase64String(encryptResult.Ciphertext); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment