Код: Выделить всё
az keyvault key encrypt --id "https://myhsmtest.managedhsm.azure.net/keys/aes256/1234aed127f8009e15d6c3a883b91f21" --algorithm A256GCM --value "123" --data-type plaintext
Код: Выделить всё
{
"aad": null,
"algorithm": "A256GCM",
"iv": "8f7f424c8548bac26c947bfd",
"kid": "https://myhsmtest.managedhsm.azure.net/keys/aes256/1234aed127f8009e15d6c3a883b91f21",
"result": "PtLm",
"tag": "e96de8eee3e194529095ef196f54cef0"
}
Код: Выделить всё
var json =
"{\n \"aad\": null,\n \"algorithm\": \"A256GCM\",\n \"iv\": \"8f7f424c8548bac26c947bfd\",\n \"kid\": \"https://myhsmtest.managedhsm.azure.net/keys/aes256/1234aed127f8009e15d6c3a883b91f21\",\n \"result\": \"PtLm\",\n \"tag\": \"e96de8eee3e194529095ef196f54cef0\"\n}";
var jsonDocument = JsonDocument.Parse(json);
var cipherText = jsonDocument.RootElement.GetProperty("result").GetString();
var iv = jsonDocument.RootElement.GetProperty("iv").GetString();
var tag = jsonDocument.RootElement.GetProperty("tag").GetString();
var cipherTextBytes = Convert.FromBase64String(cipherText);
var ivBytes = Convert.FromBase64String(iv);
var tagBytes = Convert.FromBase64String(tag);
var keyVaultUrl = "https://myhsmtest.managedhsm.azure.net";
var credential = new DefaultAzureCredential();
var client = new KeyClient(vaultUri: new Uri(keyVaultUrl), credential);
var cryptographyClient = client.GetCryptographyClient("aes256", "1234aed127f8009e15d6c3a883b91f21");
DecryptParameters decryptParameters = DecryptParameters.A256GcmParameters(ciphertext: cipherTextBytes, iv: ivBytes, authenticationTag: tagBytes);
var result = cryptographyClient.Decrypt(decryptParameters);
Код: Выделить всё
Azure.RequestFailedException: HSM Error: Invalid input data/params (Activity ID: e947a2ec-9f6d-11ef-846b-000d3a278b83)
Status: 400 (Bad Request)
ErrorCode: BadParameter
Content:
{"error":{"code":"BadParameter","message":"HSM Error: Invalid input data/params (Activity ID: e947a2ec-9f6d-11ef-846b-000d3a278b83)"}}
Headers:
x-ms-server-latency: REDACTED
Cache-Control: no-cache
X-Content-Type-Options: REDACTED
x-ms-request-id: e947a2ec-9f6d-11ef-846b-000d3a278b83
Strict-Transport-Security: REDACTED
Content-Security-Policy: REDACTED
X-Frame-Options: REDACTED
Content-Type: application/json; charset=utf-8
Content-Length: 134
at Azure.Security.KeyVault.KeyVaultPipeline.SendRequest(Request request, CancellationToken cancellationToken)
at Azure.Security.KeyVault.KeyVaultPipeline.SendRequest[TContent,TResult](RequestMethod method, TContent content, Func`1 resultFactory, CancellationToken cancellationToken, String[] path)
at Azure.Security.KeyVault.Keys.Cryptography.RemoteCryptographyClient.Decrypt(DecryptParameters parameters, CancellationToken cancellationToken)
at Azure.Security.KeyVault.Keys.Cryptography.RemoteCryptographyClient.Azure.Security.KeyVault.Keys.Cryptography.ICryptographyProvider.Decrypt(DecryptParameters parameters, CancellationToken cancellationToken)
at Azure.Security.KeyVault.Keys.Cryptography.CryptographyClient.Decrypt(DecryptParameters decryptParameters, CancellationToken cancellationToken)
...
Если я использую значения из этого JSON в CLI (расшифровка ключа az keyvault), это также работает хорошо.< /p>
Поэтому я предполагаю, что я плохо декодирую результат, iv и тег из JSON в байты [], но я не понимаю, что именно не так.>
Подробнее здесь: https://stackoverflow.com/questions/791 ... -azure-cli