I'm trying to use an RSA key I have already generated on my Azure Key Vault in the following way:
- Retrieve the public key
- Encrypt some textual data with it (-locally-)
- Decrypt it (in a different app) using Azure Key Vault
What I already managed to do is:
string clientId = "XYZ";
string tenantId = "ABC";
string clientSecret = "123";
string keyVaultName = "kvn";
string keyVaultKeyName = "kvkn";
string textToEncrypt = "StuffIDoNotWantYouToKnow";
ClientSecretCredential clientSecretCredential = new ClientSecretCredential(
tenantId, // your tenant id
clientId, // your AD application appId
clientSecret // your AD application app secret
);
//get key
KeyClient keyClient = new KeyClient(new Uri($"https://{keyVaultName}.vault.azure.net/"), clientSecretCredential); ;
var key = keyClient.GetKey(keyVaultKeyName);
What I'm currently struggling to understand is how to use the retrieved key to encrypt the textual data.
Any help would be appreciated!
P.S I use .NET framework 4.6.1