diff --git a/sdk/keyvault/keyvault-keys/recordings/node/cryptographyclient_all_decrypts_happen_remotely/recording_the_cryptographyclient_can_be_created_from_a_full_keyvaultkey_object.js b/sdk/keyvault/keyvault-keys/recordings/node/cryptographyclient_all_decrypts_happen_remotely/recording_the_cryptographyclient_can_be_created_from_a_full_keyvaultkey_object.js new file mode 100644 index 000000000000..f358390c8f4a --- /dev/null +++ b/sdk/keyvault/keyvault-keys/recordings/node/cryptographyclient_all_decrypts_happen_remotely/recording_the_cryptographyclient_can_be_created_from_a_full_keyvaultkey_object.js @@ -0,0 +1,683 @@ +let nock = require('nock'); + +module.exports.hash = "b41bdc942ee1fee5432bf652c816c1ae"; + +module.exports.testInfo = {"uniqueName":{},"newDate":{}} + +nock('https://keyvault_name.vault.azure.net:443', {"encodedQueryParams":true}) + .post('/keys/cryptography-client-test/create') + .query(true) + .reply(401, {"error":{"code":"Unauthorized","message":"Request is missing a Bearer or PoP token."}}, [ + 'Cache-Control', + 'no-cache', + 'Pragma', + 'no-cache', + 'Content-Length', + '87', + 'Content-Type', + 'application/json; charset=utf-8', + 'Expires', + '-1', + 'WWW-Authenticate', + 'Bearer authorization="https://login.windows.net/azure_tenant_id", resource="https://vault.azure.net"', + 'x-ms-keyvault-region', + 'westus', + 'x-ms-request-id', + '315e5ab0-f768-46bf-afd7-9d6b9aa79aeb', + 'x-ms-keyvault-service-version', + '1.1.6.0', + 'x-ms-keyvault-network-info', + 'conn_type=Ipv4;addr=52.250.2.122;act_addr_fam=InterNetwork;', + 'X-AspNet-Version', + '4.0.30319', + 'X-Powered-By', + 'ASP.NET', + 'Strict-Transport-Security', + 'max-age=31536000;includeSubDomains', + 'X-Content-Type-Options', + 'nosniff', + 'Date', + 'Mon, 22 Jun 2020 23:10:49 GMT' +]); + +nock('https://login.microsoftonline.com:443', {"encodedQueryParams":true}) + .post('/azure_tenant_id/oauth2/v2.0/token', "response_type=token&grant_type=client_credentials&client_id=azure_client_id&client_secret=azure_client_secret&scope=https%3A%2F%2Fvault.azure.net%2F.default") + .reply(200, {"token_type":"Bearer","expires_in":86399,"ext_expires_in":86399,"access_token":"access_token"}, [ + 'Cache-Control', + 'no-cache, no-store', + 'Pragma', + 'no-cache', + 'Content-Type', + 'application/json; charset=utf-8', + 'Expires', + '-1', + 'Strict-Transport-Security', + 'max-age=31536000; includeSubDomains', + 'X-Content-Type-Options', + 'nosniff', + 'x-ms-request-id', + '5d0e4842-8829-44f8-9015-6b7cde22b200', + 'x-ms-ests-server', + '2.1.10732.8 - SCUS ProdSlices', + 'P3P', + 'CP="DSP CUR OTPi IND OTRi ONL FIN"', + 'Set-Cookie', + 'fpc=AqQfiQmhpnpJmfSHyxL5MLM_aSJHAQAAAHkxg9YOAAAA; expires=Wed, 22-Jul-2020 23:10:50 GMT; path=/; secure; HttpOnly; SameSite=None', + 'Set-Cookie', + 'x-ms-gateway-slice=estsfd; path=/; SameSite=None; secure; HttpOnly', + 'Set-Cookie', + 'stsservicecookie=estsfd; path=/; SameSite=None; secure; HttpOnly', + 'Date', + 'Mon, 22 Jun 2020 23:10:49 GMT', + 'Content-Length', + '1315' +]); + +nock('https://keyvault_name.vault.azure.net:443', {"encodedQueryParams":true}) + .post('/keys/cryptography-client-test/create', {"kty":"RSA"}) + .query(true) + .reply(200, {"key":{"kid":"https://keyvault_name.vault.azure.net/keys/cryptography-client-test/1265620977234b4eb9444807249e495e","kty":"RSA","key_ops":["encrypt","decrypt","sign","verify","wrapKey","unwrapKey"],"n":"v1beOcOsyrvuqr_XFDwnU4jnP66lq5phn0mu4ktYaWOFd_XsnDw7YPwh04BEGDGEh7WM8IgfD7lmj4PYEEXNP3gkv6-dK3I0AbDUyiD3O-evfxoOSzSEQ33BwYMsasbGtso5kvUrmVMdRN_z-a_g407obEFfJ3EteH4VW281aCc6USpeCV1JGR2ZNVz7lwiD6ouM3tbF7o5Elnjx1COGn_hjUBa6JZTbtmsKYIoGEPVgW83124Z5jGKKyTUee7o5NmeSgmoZqZ2jc5N8xA3uxaPPGZbPTwATBXmCrbALszhTupD2sBYH2tBIWYKEQQgiaFEnmdreb-_recl37e6SUQ","e":"AQAB"},"attributes":{"enabled":true,"created":1592867450,"updated":1592867450,"recoveryLevel":"Recoverable+Purgeable","recoverableDays":90}}, [ + 'Cache-Control', + 'no-cache', + 'Pragma', + 'no-cache', + 'Content-Type', + 'application/json; charset=utf-8', + 'Expires', + '-1', + 'x-ms-keyvault-region', + 'westus', + 'x-ms-request-id', + '7f171014-c889-4d01-baf8-a6e6eb967ab3', + 'x-ms-keyvault-service-version', + '1.1.6.0', + 'x-ms-keyvault-network-info', + 'conn_type=Ipv4;addr=52.250.2.122;act_addr_fam=InterNetwork;', + 'X-AspNet-Version', + '4.0.30319', + 'X-Powered-By', + 'ASP.NET', + 'Strict-Transport-Security', + 'max-age=31536000;includeSubDomains', + 'X-Content-Type-Options', + 'nosniff', + 'Date', + 'Mon, 22 Jun 2020 23:10:49 GMT', + 'Content-Length', + '714' +]); + +nock('https://keyvault_name.vault.azure.net:443', {"encodedQueryParams":true}) + .post('/keys/cryptoKeyName-theCryptographyClientcanbecreatedfromafullKeyVaultKeyobject-/create', {"kty":"RSA"}) + .query(true) + .reply(200, {"key":{"kid":"https://keyvault_name.vault.azure.net/keys/cryptoKeyName-theCryptographyClientcanbecreatedfromafullKeyVaultKeyobject-/5d2250270e674035912c541b3bde4246","kty":"RSA","key_ops":["encrypt","decrypt","sign","verify","wrapKey","unwrapKey"],"n":"1OhnNv2zj053gLuYz90gXxfgzaAOREdV3Nqxrb3r1Oc1Qb2fg81LFdJnANi5Qi9V-BZLuw8JZlPRDvQTjp7yJ3JUhLXLqd5mhFxkIx-SF8CkleB8_QdZuHeWgJ1w-vf-romDjEh9Ma81O8nAhb6GKTpbYczD89xKCa-QlBpWcgtHcyq4b4vD0MnOqKCoyzMsw-KGkibRLzWwbi1gZRm-q467vD9sTS9EEgd-rXoYQTtonhRTv1SOm6pWsRbtQld8cBlwg4_i4epTPjIjBQBStZktCyDkpH4zKaOn_zAOBxIIYA7aTgN42nojVE3CmHRXbbSh3BSRfH_3k8hxdav8lw","e":"AQAB"},"attributes":{"enabled":true,"created":1592867450,"updated":1592867450,"recoveryLevel":"Recoverable+Purgeable","recoverableDays":90}}, [ + 'Cache-Control', + 'no-cache', + 'Pragma', + 'no-cache', + 'Content-Type', + 'application/json; charset=utf-8', + 'Expires', + '-1', + 'x-ms-keyvault-region', + 'westus', + 'x-ms-request-id', + '428592b9-e48c-4b0d-9abb-9eec84d3c015', + 'x-ms-keyvault-service-version', + '1.1.6.0', + 'x-ms-keyvault-network-info', + 'conn_type=Ipv4;addr=52.250.2.122;act_addr_fam=InterNetwork;', + 'X-AspNet-Version', + '4.0.30319', + 'X-Powered-By', + 'ASP.NET', + 'Strict-Transport-Security', + 'max-age=31536000;includeSubDomains', + 'X-Content-Type-Options', + 'nosniff', + 'Date', + 'Mon, 22 Jun 2020 23:10:49 GMT', + 'Content-Length', + '764' +]); + +nock('https://keyvault_name.vault.azure.net:443', {"encodedQueryParams":true}) + .post('/keys/cryptoKeyName-theCryptographyClientcanbecreatedfromafullKeyVaultKeyobject-/5d2250270e674035912c541b3bde4246/decrypt') + .query(true) + .reply(401, {"error":{"code":"Unauthorized","message":"Request is missing a Bearer or PoP token."}}, [ + 'Cache-Control', + 'no-cache', + 'Pragma', + 'no-cache', + 'Content-Length', + '87', + 'Content-Type', + 'application/json; charset=utf-8', + 'Expires', + '-1', + 'WWW-Authenticate', + 'Bearer authorization="https://login.windows.net/azure_tenant_id", resource="https://vault.azure.net"', + 'x-ms-keyvault-region', + 'westus', + 'x-ms-request-id', + 'b63a2e15-865c-4685-8d31-830659aee025', + 'x-ms-keyvault-service-version', + '1.1.6.0', + 'x-ms-keyvault-network-info', + 'conn_type=Ipv4;addr=52.250.2.122;act_addr_fam=InterNetwork;', + 'X-AspNet-Version', + '4.0.30319', + 'X-Powered-By', + 'ASP.NET', + 'Strict-Transport-Security', + 'max-age=31536000;includeSubDomains', + 'X-Content-Type-Options', + 'nosniff', + 'Date', + 'Mon, 22 Jun 2020 23:10:50 GMT' +]); + +nock('https://login.microsoftonline.com:443', {"encodedQueryParams":true}) + .post('/azure_tenant_id/oauth2/v2.0/token', "response_type=token&grant_type=client_credentials&client_id=azure_client_id&client_secret=azure_client_secret&scope=https%3A%2F%2Fvault.azure.net%2F.default") + .reply(200, {"token_type":"Bearer","expires_in":86399,"ext_expires_in":86399,"access_token":"access_token"}, [ + 'Cache-Control', + 'no-cache, no-store', + 'Pragma', + 'no-cache', + 'Content-Type', + 'application/json; charset=utf-8', + 'Expires', + '-1', + 'Strict-Transport-Security', + 'max-age=31536000; includeSubDomains', + 'X-Content-Type-Options', + 'nosniff', + 'x-ms-request-id', + 'e35675ea-f5f9-49b3-8f3a-4e2401d3bd00', + 'x-ms-ests-server', + '2.1.10732.8 - EUS ProdSlices', + 'P3P', + 'CP="DSP CUR OTPi IND OTRi ONL FIN"', + 'Set-Cookie', + 'fpc=AqQfiQmhpnpJmfSHyxL5MLM_aSJHAgAAAHkxg9YOAAAA; expires=Wed, 22-Jul-2020 23:10:50 GMT; path=/; secure; HttpOnly; SameSite=None', + 'Set-Cookie', + 'x-ms-gateway-slice=estsfd; path=/; SameSite=None; secure; HttpOnly', + 'Set-Cookie', + 'stsservicecookie=estsfd; path=/; SameSite=None; secure; HttpOnly', + 'Date', + 'Mon, 22 Jun 2020 23:10:50 GMT', + 'Content-Length', + '1315' +]); + +nock('https://keyvault_name.vault.azure.net:443', {"encodedQueryParams":true}) + .post('/keys/cryptoKeyName-theCryptographyClientcanbecreatedfromafullKeyVaultKeyobject-/5d2250270e674035912c541b3bde4246/decrypt', {"alg":"RSA1_5","value":"RS5lSDLemdr6m1TJtCnpxmGwxFkyctRrFSfuv34ReP6wRbu1v-cbfcKL6GwIK6obkLE7JdeB3_xUS0uVmRIpNxPlIzBvgyfLiiyPbhLbcOw9mMuy3uhXA-qywu6Sy1KbNoNCXdKIAjj_ptwSgr4WGSwFr6_Tt9iEwzmC5FpfabrqArKsqDtaoQ_ABSUvoXC70omk_y44lkaF6ZBPZIDazPEf_gCg6plU7l0YIDNKIVkcsMqRT9_-2beLVGe_pPpY2I13_nfZ2_dMjZnLGATzkCdizZTnQ62HYDdCraI-elgBL_LU8h5nvU4Ey_mY81sLe14rK4codxfBFi2HbJUnKA"}) + .query(true) + .reply(200, {"kid":"https://keyvault_name.vault.azure.net/keys/cryptoKeyName-theCryptographyClientcanbecreatedfromafullKeyVaultKeyobject-/5d2250270e674035912c541b3bde4246","value":"dGhlIENyeXB0b2dyYXBoeUNsaWVudCBjYW4gYmUgY3JlYXRlZCBmcm9tIGEgZnVsbCBLZXlWYXVsdEtleSBvYmplY3Q"}, [ + 'Cache-Control', + 'no-cache', + 'Pragma', + 'no-cache', + 'Content-Type', + 'application/json; charset=utf-8', + 'Expires', + '-1', + 'x-ms-keyvault-region', + 'westus', + 'x-ms-request-id', + '4d2c7c09-8236-4c0f-afd6-e91f6b4f0591', + 'x-ms-keyvault-service-version', + '1.1.6.0', + 'x-ms-keyvault-network-info', + 'conn_type=Ipv4;addr=52.250.2.122;act_addr_fam=InterNetwork;', + 'X-AspNet-Version', + '4.0.30319', + 'X-Powered-By', + 'ASP.NET', + 'Strict-Transport-Security', + 'max-age=31536000;includeSubDomains', + 'X-Content-Type-Options', + 'nosniff', + 'Date', + 'Mon, 22 Jun 2020 23:10:50 GMT', + 'Content-Length', + '283' +]); + +nock('https://keyvault_name.vault.azure.net:443', {"encodedQueryParams":true}) + .delete('/keys/cryptography-client-test') + .query(true) + .reply(200, {"recoveryId":"https://keyvault_name.vault.azure.net/deletedkeys/cryptography-client-test","deletedDate":1592867450,"scheduledPurgeDate":1600643450,"key":{"kid":"https://keyvault_name.vault.azure.net/keys/cryptography-client-test/1265620977234b4eb9444807249e495e","kty":"RSA","key_ops":["encrypt","decrypt","sign","verify","wrapKey","unwrapKey"],"n":"v1beOcOsyrvuqr_XFDwnU4jnP66lq5phn0mu4ktYaWOFd_XsnDw7YPwh04BEGDGEh7WM8IgfD7lmj4PYEEXNP3gkv6-dK3I0AbDUyiD3O-evfxoOSzSEQ33BwYMsasbGtso5kvUrmVMdRN_z-a_g407obEFfJ3EteH4VW281aCc6USpeCV1JGR2ZNVz7lwiD6ouM3tbF7o5Elnjx1COGn_hjUBa6JZTbtmsKYIoGEPVgW83124Z5jGKKyTUee7o5NmeSgmoZqZ2jc5N8xA3uxaPPGZbPTwATBXmCrbALszhTupD2sBYH2tBIWYKEQQgiaFEnmdreb-_recl37e6SUQ","e":"AQAB"},"attributes":{"enabled":true,"created":1592867450,"updated":1592867450,"recoveryLevel":"Recoverable+Purgeable","recoverableDays":90}}, [ + 'Cache-Control', + 'no-cache', + 'Pragma', + 'no-cache', + 'Content-Type', + 'application/json; charset=utf-8', + 'Expires', + '-1', + 'x-ms-keyvault-region', + 'westus', + 'x-ms-request-id', + '25de079a-6a89-435b-9cb2-dac90bcf439e', + 'x-ms-keyvault-service-version', + '1.1.6.0', + 'x-ms-keyvault-network-info', + 'conn_type=Ipv4;addr=52.250.2.122;act_addr_fam=InterNetwork;', + 'X-AspNet-Version', + '4.0.30319', + 'X-Powered-By', + 'ASP.NET', + 'Strict-Transport-Security', + 'max-age=31536000;includeSubDomains', + 'X-Content-Type-Options', + 'nosniff', + 'Date', + 'Mon, 22 Jun 2020 23:10:50 GMT', + 'Content-Length', + '882' +]); + +nock('https://keyvault_name.vault.azure.net:443', {"encodedQueryParams":true}) + .get('/deletedkeys/cryptography-client-test') + .query(true) + .reply(404, {"error":{"code":"KeyNotFound","message":"Deleted Key not found: cryptography-client-test"}}, [ + 'Cache-Control', + 'no-cache', + 'Pragma', + 'no-cache', + 'Content-Length', + '108', + 'Content-Type', + 'application/json; charset=utf-8', + 'Expires', + '-1', + 'x-ms-keyvault-region', + 'westus', + 'x-ms-request-id', + '5e87c113-40c9-4a16-bee1-7f192242f39c', + 'x-ms-keyvault-service-version', + '1.1.6.0', + 'x-ms-keyvault-network-info', + 'conn_type=Ipv4;addr=52.250.2.122;act_addr_fam=InterNetwork;', + 'X-AspNet-Version', + '4.0.30319', + 'X-Powered-By', + 'ASP.NET', + 'Strict-Transport-Security', + 'max-age=31536000;includeSubDomains', + 'X-Content-Type-Options', + 'nosniff', + 'Date', + 'Mon, 22 Jun 2020 23:10:50 GMT' +]); + +nock('https://keyvault_name.vault.azure.net:443', {"encodedQueryParams":true}) + .get('/deletedkeys/cryptography-client-test') + .query(true) + .reply(404, {"error":{"code":"KeyNotFound","message":"Deleted Key not found: cryptography-client-test"}}, [ + 'Cache-Control', + 'no-cache', + 'Pragma', + 'no-cache', + 'Content-Length', + '108', + 'Content-Type', + 'application/json; charset=utf-8', + 'Expires', + '-1', + 'x-ms-keyvault-region', + 'westus', + 'x-ms-request-id', + 'a381c8f2-1f46-4d9a-b8f7-79c2a475610b', + 'x-ms-keyvault-service-version', + '1.1.6.0', + 'x-ms-keyvault-network-info', + 'conn_type=Ipv4;addr=52.250.2.122;act_addr_fam=InterNetwork;', + 'X-AspNet-Version', + '4.0.30319', + 'X-Powered-By', + 'ASP.NET', + 'Strict-Transport-Security', + 'max-age=31536000;includeSubDomains', + 'X-Content-Type-Options', + 'nosniff', + 'Date', + 'Mon, 22 Jun 2020 23:10:50 GMT' +]); + +nock('https://keyvault_name.vault.azure.net:443', {"encodedQueryParams":true}) + .get('/deletedkeys/cryptography-client-test') + .query(true) + .reply(404, {"error":{"code":"KeyNotFound","message":"Deleted Key not found: cryptography-client-test"}}, [ + 'Cache-Control', + 'no-cache', + 'Pragma', + 'no-cache', + 'Content-Length', + '108', + 'Content-Type', + 'application/json; charset=utf-8', + 'Expires', + '-1', + 'x-ms-keyvault-region', + 'westus', + 'x-ms-request-id', + 'c2b17c41-39de-492e-a19b-f4d34b9d62d0', + 'x-ms-keyvault-service-version', + '1.1.6.0', + 'x-ms-keyvault-network-info', + 'conn_type=Ipv4;addr=52.250.2.122;act_addr_fam=InterNetwork;', + 'X-AspNet-Version', + '4.0.30319', + 'X-Powered-By', + 'ASP.NET', + 'Strict-Transport-Security', + 'max-age=31536000;includeSubDomains', + 'X-Content-Type-Options', + 'nosniff', + 'Date', + 'Mon, 22 Jun 2020 23:10:53 GMT' +]); + +nock('https://keyvault_name.vault.azure.net:443', {"encodedQueryParams":true}) + .get('/deletedkeys/cryptography-client-test') + .query(true) + .reply(404, {"error":{"code":"KeyNotFound","message":"Deleted Key not found: cryptography-client-test"}}, [ + 'Cache-Control', + 'no-cache', + 'Pragma', + 'no-cache', + 'Content-Length', + '108', + 'Content-Type', + 'application/json; charset=utf-8', + 'Expires', + '-1', + 'x-ms-keyvault-region', + 'westus', + 'x-ms-request-id', + 'cc488518-16cf-4353-9473-c7a1cd05df0e', + 'x-ms-keyvault-service-version', + '1.1.6.0', + 'x-ms-keyvault-network-info', + 'conn_type=Ipv4;addr=52.250.2.122;act_addr_fam=InterNetwork;', + 'X-AspNet-Version', + '4.0.30319', + 'X-Powered-By', + 'ASP.NET', + 'Strict-Transport-Security', + 'max-age=31536000;includeSubDomains', + 'X-Content-Type-Options', + 'nosniff', + 'Date', + 'Mon, 22 Jun 2020 23:10:55 GMT' +]); + +nock('https://keyvault_name.vault.azure.net:443', {"encodedQueryParams":true}) + .get('/deletedkeys/cryptography-client-test') + .query(true) + .reply(404, {"error":{"code":"KeyNotFound","message":"Deleted Key not found: cryptography-client-test"}}, [ + 'Cache-Control', + 'no-cache', + 'Pragma', + 'no-cache', + 'Content-Length', + '108', + 'Content-Type', + 'application/json; charset=utf-8', + 'Expires', + '-1', + 'x-ms-keyvault-region', + 'westus', + 'x-ms-request-id', + '5f05b8c1-48fb-4f8d-880c-ad63879a914b', + 'x-ms-keyvault-service-version', + '1.1.6.0', + 'x-ms-keyvault-network-info', + 'conn_type=Ipv4;addr=52.250.2.122;act_addr_fam=InterNetwork;', + 'X-AspNet-Version', + '4.0.30319', + 'X-Powered-By', + 'ASP.NET', + 'Strict-Transport-Security', + 'max-age=31536000;includeSubDomains', + 'X-Content-Type-Options', + 'nosniff', + 'Date', + 'Mon, 22 Jun 2020 23:10:56 GMT' +]); + +nock('https://keyvault_name.vault.azure.net:443', {"encodedQueryParams":true}) + .get('/deletedkeys/cryptography-client-test') + .query(true) + .reply(404, {"error":{"code":"KeyNotFound","message":"Deleted Key not found: cryptography-client-test"}}, [ + 'Cache-Control', + 'no-cache', + 'Pragma', + 'no-cache', + 'Content-Length', + '108', + 'Content-Type', + 'application/json; charset=utf-8', + 'Expires', + '-1', + 'x-ms-keyvault-region', + 'westus', + 'x-ms-request-id', + '1754e8fa-e5eb-4efa-af57-96e73c81ced0', + 'x-ms-keyvault-service-version', + '1.1.6.0', + 'x-ms-keyvault-network-info', + 'conn_type=Ipv4;addr=52.250.2.122;act_addr_fam=InterNetwork;', + 'X-AspNet-Version', + '4.0.30319', + 'X-Powered-By', + 'ASP.NET', + 'Strict-Transport-Security', + 'max-age=31536000;includeSubDomains', + 'X-Content-Type-Options', + 'nosniff', + 'Date', + 'Mon, 22 Jun 2020 23:10:58 GMT' +]); + +nock('https://keyvault_name.vault.azure.net:443', {"encodedQueryParams":true}) + .get('/deletedkeys/cryptography-client-test') + .query(true) + .reply(404, {"error":{"code":"KeyNotFound","message":"Deleted Key not found: cryptography-client-test"}}, [ + 'Cache-Control', + 'no-cache', + 'Pragma', + 'no-cache', + 'Content-Length', + '108', + 'Content-Type', + 'application/json; charset=utf-8', + 'Expires', + '-1', + 'x-ms-keyvault-region', + 'westus', + 'x-ms-request-id', + '9a51267b-a467-45ba-a049-bf4539269856', + 'x-ms-keyvault-service-version', + '1.1.6.0', + 'x-ms-keyvault-network-info', + 'conn_type=Ipv4;addr=52.250.2.122;act_addr_fam=InterNetwork;', + 'X-AspNet-Version', + '4.0.30319', + 'X-Powered-By', + 'ASP.NET', + 'Strict-Transport-Security', + 'max-age=31536000;includeSubDomains', + 'X-Content-Type-Options', + 'nosniff', + 'Date', + 'Mon, 22 Jun 2020 23:11:00 GMT' +]); + +nock('https://keyvault_name.vault.azure.net:443', {"encodedQueryParams":true}) + .get('/deletedkeys/cryptography-client-test') + .query(true) + .reply(404, {"error":{"code":"KeyNotFound","message":"Deleted Key not found: cryptography-client-test"}}, [ + 'Cache-Control', + 'no-cache', + 'Pragma', + 'no-cache', + 'Content-Length', + '108', + 'Content-Type', + 'application/json; charset=utf-8', + 'Expires', + '-1', + 'x-ms-keyvault-region', + 'westus', + 'x-ms-request-id', + '41974e46-c055-41bd-b3fe-abb46bd5e194', + 'x-ms-keyvault-service-version', + '1.1.6.0', + 'x-ms-keyvault-network-info', + 'conn_type=Ipv4;addr=52.250.2.122;act_addr_fam=InterNetwork;', + 'X-AspNet-Version', + '4.0.30319', + 'X-Powered-By', + 'ASP.NET', + 'Strict-Transport-Security', + 'max-age=31536000;includeSubDomains', + 'X-Content-Type-Options', + 'nosniff', + 'Date', + 'Mon, 22 Jun 2020 23:11:02 GMT' +]); + +nock('https://keyvault_name.vault.azure.net:443', {"encodedQueryParams":true}) + .get('/deletedkeys/cryptography-client-test') + .query(true) + .reply(404, {"error":{"code":"KeyNotFound","message":"Deleted Key not found: cryptography-client-test"}}, [ + 'Cache-Control', + 'no-cache', + 'Pragma', + 'no-cache', + 'Content-Length', + '108', + 'Content-Type', + 'application/json; charset=utf-8', + 'Expires', + '-1', + 'x-ms-keyvault-region', + 'westus', + 'x-ms-request-id', + '4679207c-cab8-4a95-b88a-9f22df5bd4d0', + 'x-ms-keyvault-service-version', + '1.1.6.0', + 'x-ms-keyvault-network-info', + 'conn_type=Ipv4;addr=52.250.2.122;act_addr_fam=InterNetwork;', + 'X-AspNet-Version', + '4.0.30319', + 'X-Powered-By', + 'ASP.NET', + 'Strict-Transport-Security', + 'max-age=31536000;includeSubDomains', + 'X-Content-Type-Options', + 'nosniff', + 'Date', + 'Mon, 22 Jun 2020 23:11:05 GMT' +]); + +nock('https://keyvault_name.vault.azure.net:443', {"encodedQueryParams":true}) + .get('/deletedkeys/cryptography-client-test') + .query(true) + .reply(404, {"error":{"code":"KeyNotFound","message":"Deleted Key not found: cryptography-client-test"}}, [ + 'Cache-Control', + 'no-cache', + 'Pragma', + 'no-cache', + 'Content-Length', + '108', + 'Content-Type', + 'application/json; charset=utf-8', + 'Expires', + '-1', + 'x-ms-keyvault-region', + 'westus', + 'x-ms-request-id', + '9b693b5f-cc67-4616-8298-af604e8d3ee1', + 'x-ms-keyvault-service-version', + '1.1.6.0', + 'x-ms-keyvault-network-info', + 'conn_type=Ipv4;addr=52.250.2.122;act_addr_fam=InterNetwork;', + 'X-AspNet-Version', + '4.0.30319', + 'X-Powered-By', + 'ASP.NET', + 'Strict-Transport-Security', + 'max-age=31536000;includeSubDomains', + 'X-Content-Type-Options', + 'nosniff', + 'Date', + 'Mon, 22 Jun 2020 23:11:06 GMT' +]); + +nock('https://keyvault_name.vault.azure.net:443', {"encodedQueryParams":true}) + .get('/deletedkeys/cryptography-client-test') + .query(true) + .reply(200, {"recoveryId":"https://keyvault_name.vault.azure.net/deletedkeys/cryptography-client-test","deletedDate":1592867450,"scheduledPurgeDate":1600643450,"key":{"kid":"https://keyvault_name.vault.azure.net/keys/cryptography-client-test/1265620977234b4eb9444807249e495e","kty":"RSA","key_ops":["encrypt","decrypt","sign","verify","wrapKey","unwrapKey"],"n":"v1beOcOsyrvuqr_XFDwnU4jnP66lq5phn0mu4ktYaWOFd_XsnDw7YPwh04BEGDGEh7WM8IgfD7lmj4PYEEXNP3gkv6-dK3I0AbDUyiD3O-evfxoOSzSEQ33BwYMsasbGtso5kvUrmVMdRN_z-a_g407obEFfJ3EteH4VW281aCc6USpeCV1JGR2ZNVz7lwiD6ouM3tbF7o5Elnjx1COGn_hjUBa6JZTbtmsKYIoGEPVgW83124Z5jGKKyTUee7o5NmeSgmoZqZ2jc5N8xA3uxaPPGZbPTwATBXmCrbALszhTupD2sBYH2tBIWYKEQQgiaFEnmdreb-_recl37e6SUQ","e":"AQAB"},"attributes":{"enabled":true,"created":1592867450,"updated":1592867450,"recoveryLevel":"Recoverable+Purgeable","recoverableDays":90}}, [ + 'Cache-Control', + 'no-cache', + 'Pragma', + 'no-cache', + 'Content-Type', + 'application/json; charset=utf-8', + 'Expires', + '-1', + 'x-ms-keyvault-region', + 'westus', + 'x-ms-request-id', + '939a08a7-9eed-4317-bb7e-584c9d749201', + 'x-ms-keyvault-service-version', + '1.1.6.0', + 'x-ms-keyvault-network-info', + 'conn_type=Ipv4;addr=52.250.2.122;act_addr_fam=InterNetwork;', + 'X-AspNet-Version', + '4.0.30319', + 'X-Powered-By', + 'ASP.NET', + 'Strict-Transport-Security', + 'max-age=31536000;includeSubDomains', + 'X-Content-Type-Options', + 'nosniff', + 'Date', + 'Mon, 22 Jun 2020 23:11:09 GMT', + 'Content-Length', + '882' +]); + +nock('https://keyvault_name.vault.azure.net:443', {"encodedQueryParams":true}) + .delete('/deletedkeys/cryptography-client-test') + .query(true) + .reply(204, "", [ + 'Cache-Control', + 'no-cache', + 'Pragma', + 'no-cache', + 'Expires', + '-1', + 'x-ms-keyvault-region', + 'westus', + 'x-ms-request-id', + 'd2ef38b0-914c-475e-b275-573501eab806', + 'x-ms-keyvault-service-version', + '1.1.6.0', + 'x-ms-keyvault-network-info', + 'conn_type=Ipv4;addr=52.250.2.122;act_addr_fam=InterNetwork;', + 'X-AspNet-Version', + '4.0.30319', + 'X-Powered-By', + 'ASP.NET', + 'Strict-Transport-Security', + 'max-age=31536000;includeSubDomains', + 'X-Content-Type-Options', + 'nosniff', + 'Date', + 'Mon, 22 Jun 2020 23:11:09 GMT' +]); diff --git a/sdk/keyvault/keyvault-keys/review/keyvault-keys.api.md b/sdk/keyvault/keyvault-keys/review/keyvault-keys.api.md index 9ba2f9bc8edf..fa382fe0d745 100644 --- a/sdk/keyvault/keyvault-keys/review/keyvault-keys.api.md +++ b/sdk/keyvault/keyvault-keys/review/keyvault-keys.api.md @@ -50,8 +50,7 @@ export interface CreateRsaKeyOptions extends CreateKeyOptions { // @public export class CryptographyClient { - constructor(key: string | KeyVaultKey, // keyUrl or KeyVaultKey - credential: TokenCredential, pipelineOptions?: CryptographyClientOptions); + constructor(key: string | KeyVaultKey, credential: TokenCredential, pipelineOptions?: CryptographyClientOptions); decrypt(algorithm: EncryptionAlgorithm, ciphertext: Uint8Array, options?: DecryptOptions): Promise; encrypt(algorithm: EncryptionAlgorithm, plaintext: Uint8Array, options?: EncryptOptions): Promise; sign(algorithm: SignatureAlgorithm, digest: Uint8Array, options?: SignOptions): Promise; diff --git a/sdk/keyvault/keyvault-keys/samples/javascript/cryptography.js b/sdk/keyvault/keyvault-keys/samples/javascript/cryptography.js index 29cfae897ab3..2631b7038f0d 100644 --- a/sdk/keyvault/keyvault-keys/samples/javascript/cryptography.js +++ b/sdk/keyvault/keyvault-keys/samples/javascript/cryptography.js @@ -28,7 +28,9 @@ async function main() { // Connection to Azure Key Vault Cryptography functionality let myWorkKey = await client.createKey(keyName, "RSA"); - const cryptoClient = new CryptographyClient(myWorkKey.id, credential); + const cryptoClient = new CryptographyClient( + myWorkKey // You can use either the key or the key Id i.e. its url to create a CryptographyClient. + , credential); // Sign and Verify const signatureValue = "MySignature"; diff --git a/sdk/keyvault/keyvault-keys/samples/typescript/src/cryptography.ts b/sdk/keyvault/keyvault-keys/samples/typescript/src/cryptography.ts index c5b852f26702..da03877eac41 100644 --- a/sdk/keyvault/keyvault-keys/samples/typescript/src/cryptography.ts +++ b/sdk/keyvault/keyvault-keys/samples/typescript/src/cryptography.ts @@ -29,7 +29,9 @@ export async function main(): Promise { // Connection to Azure Key Vault Cryptography functionality const myWorkKey = await client.createKey(keyName, "RSA"); - const cryptoClient = new CryptographyClient(myWorkKey.id!, credential); + const cryptoClient = new CryptographyClient( + myWorkKey.id! // You can use either the key or the key Id i.e. its url to create a CryptographyClient. + , credential); // Sign and Verify const signatureValue = "MySignature"; diff --git a/sdk/keyvault/keyvault-keys/src/cryptographyClient.ts b/sdk/keyvault/keyvault-keys/src/cryptographyClient.ts index 61e810efe613..3a2c57b4e6c5 100644 --- a/sdk/keyvault/keyvault-keys/src/cryptographyClient.ts +++ b/sdk/keyvault/keyvault-keys/src/cryptographyClient.ts @@ -665,14 +665,14 @@ export class CryptographyClient { * // or * let client = new CryptographyClient(keyVaultKey, credentials); * ``` - * @param key The key to use during cryptography tasks. + * @param key The key to use during cryptography tasks. You can also pass the identifier of the key i.e its url here. * @param {TokenCredential} credential An object that implements the `TokenCredential` interface used to authenticate requests to the service. Use the @azure/identity package to create a credential that suits your needs. * @param {PipelineOptions} [pipelineOptions={}] Optional. Pipeline options used to configure Key Vault API requests. * Omit this parameter to use the default pipeline configuration. * @memberof CryptographyClient */ constructor( - key: string | KeyVaultKey, // keyUrl or KeyVaultKey + key: string | KeyVaultKey, credential: TokenCredential, pipelineOptions: CryptographyClientOptions = {} ) { diff --git a/sdk/keyvault/keyvault-keys/test/public/crypto.spec.ts b/sdk/keyvault/keyvault-keys/test/public/crypto.spec.ts index 2a4d223d9bc6..25f2b8e687a3 100644 --- a/sdk/keyvault/keyvault-keys/test/public/crypto.spec.ts +++ b/sdk/keyvault/keyvault-keys/test/public/crypto.spec.ts @@ -4,7 +4,7 @@ import * as assert from "assert"; import { createHash, publicEncrypt } from "crypto"; import * as constants from "constants"; -import { isRecordMode, Recorder } from "@azure/test-utils-recorder"; +import { isRecordMode, Recorder, env } from "@azure/test-utils-recorder"; import { ClientSecretCredential } from "@azure/identity"; import { isNode } from "@azure/core-http"; @@ -15,6 +15,7 @@ import TestClient from "../utils/testClient"; import { stringToUint8Array, uint8ArrayToString } from "../utils/crypto"; describe("CryptographyClient (all decrypts happen remotely)", () => { + const keyPrefix = `crypto${env.KEY_NAME || "KeyName"}`; let client: KeyClient; let testClient: TestClient; let cryptoClient: CryptographyClient; @@ -83,6 +84,18 @@ describe("CryptographyClient (all decrypts happen remotely)", () => { const decryptedText = uint8ArrayToString(decryptResult.result); assert.equal(text, decryptedText); }); + + it("the CryptographyClient can be created from a full KeyVaultKey object", async function() { + const keyName = testClient.formatName(`${keyPrefix}-${this!.test!.title}-${keySuffix}`); + const keyVaultKey = await client.createKey(keyName, "RSA"); + const cryptoClientFromKey = new CryptographyClient(keyVaultKey, credential); + + const text = this.test!.title; + const encryptResult = await cryptoClientFromKey.encrypt("RSA1_5", stringToUint8Array(text)); + const decryptResult = await cryptoClientFromKey.decrypt("RSA1_5", encryptResult.result); + const decryptedText = uint8ArrayToString(decryptResult.result); + assert.equal(text, decryptedText); + }); } // Local encryption is only supported in NodeJS.