-
Notifications
You must be signed in to change notification settings - Fork 150
Update docs #3678
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Update docs #3678
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
757f643
begining
gearama 3c1550e
update readmes
gearama 75dc221
Update sdk/keyvault/azure-security-keyvault-certificates/CHANGELOG.md
gearama 3730234
Update sdk/keyvault/azure-security-keyvault-keys/CHANGELOG.md
gearama 6a7b58e
Update sdk/keyvault/azure-security-keyvault-keys/README.md
gearama 4170772
Update sdk/keyvault/azure-security-keyvault-secrets/CHANGELOG.md
gearama File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
106 changes: 106 additions & 0 deletions
106
sdk/keyvault/azure-security-keyvault-keys/samples/sample6_wrap_unwrap.md
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| # Creating, wrapping and unwrapping keys | ||
|
|
||
| This sample demonstrates how to create, get, wrap and unwrap a key in Azure Key Vault. | ||
| To get started, you'll need a URI to an Azure Key Vault. See the [README](https://github.com/Azure/azure-sdk-for-cpp/blob/main/sdk/keyvault/azure-security-keyvault-keys/README.md) for links and instructions. | ||
|
|
||
| ## Creating a KeyClient | ||
|
|
||
| To create a new `KeyClient` to create, get, update, or delete keys, you need the endpoint to an Azure Key Vault and credentials. | ||
|
|
||
| Key Vault Keys client for C++ currently supports the `ClientSecretCredential` for authenticating. | ||
|
|
||
| In the sample below, you can create a credential by setting the Tenant ID, Client ID and client secret as environment variables. | ||
|
|
||
| ```cpp Snippet:KeysSample6CreateCredential | ||
| auto tenantId = std::getenv("AZURE_TENANT_ID"); | ||
| auto clientId = std::getenv("AZURE_CLIENT_ID"); | ||
| auto clientSecret = std::getenv("AZURE_CLIENT_SECRET"); | ||
| auto credential = std::make_shared<Azure::Identity::ClientSecretCredential>(tenantId, clientId, clientSecret); | ||
| ``` | ||
|
|
||
| Then, in the sample below, you can set `keyVaultUrl` based on an environment variable, configuration setting, or any way that works for your application. | ||
|
|
||
| ```cpp Snippet:KeysSample6KeyClient | ||
| KeyClient keyClient(std::getenv("AZURE_KEYVAULT_URL"), credential); | ||
| ``` | ||
|
|
||
| ## Creating a key | ||
|
|
||
| Let's create an RSA key valid for 1 year. | ||
| If the key already exists in the Azure Key Vault, then a new version of the key is created. | ||
|
|
||
| ```cpp Snippet:KeysSample6CreateKey | ||
| auto rsaKey = CreateRsaKeyOptions(rsaKeyName); | ||
| rsaKey.KeySize = 2048; | ||
| rsaKey.ExpiresOn = std::chrono::system_clock::now() + std::chrono::hours(24 * 365); | ||
|
|
||
| keyClient.CreateRsaKey(rsaKey); | ||
| ``` | ||
|
|
||
| ## Creating the CryptographyClient | ||
|
|
||
| Let's create a CryptographyClient instance using the created key. | ||
|
|
||
| ```cpp Snippet:KeysSample6CryptoClient | ||
| CryptographyClient cryptoClient(cloudRsaKey.Id(), credential); | ||
|
|
||
| ``` | ||
|
|
||
| ## Wrap the key | ||
|
|
||
| Now we will wrap the key. | ||
| ```cpp Snippet:KeysSample6WrapKey | ||
| // keyDataSource simulates a symmetric private key created locally in the system. It is not | ||
| // relevant for the sample how to create the private key as it depends on the OS. | ||
| // For example, on linux, the key can be created using openSSL. | ||
| uint8_t const keyDataSource[] | ||
| = "MIIBOgIBAAJBAKUFtjMCrEZzg30Rb5EQnFy6fFUTn3wwVPM9yW4Icn7EMk34ic+" | ||
| "3CYytbOqbRQDDUtbyUCdMEu2OZ0RPqL4GWMECAwEAAQJAcHi7HHs25XF3bbeDfbB/" | ||
| "kae8c9PDAEaEr6At+......"; | ||
| std::vector<uint8_t> keyData(std::begin(keyDataSource), std::end(keyDataSource)); | ||
| std::cout << " - Using a sample generated key: " << Azure::Core::Convert::Base64Encode(keyData) | ||
| << std::endl; | ||
|
|
||
| auto wrapResult = cryptoClient.WrapKey(KeyWrapAlgorithm::RsaOaep, keyData).Value; | ||
| std::cout << " - Encrypted data using the algorithm " << wrapResult.Algorithm.ToString() | ||
| << ", with key " << wrapResult.KeyId << ". The resulting encrypted data is: " | ||
| << Azure::Core::Convert::Base64Encode(wrapResult.EncryptedKey) << std::endl; | ||
|
|
||
| ``` | ||
|
|
||
| ## Unwrap the key | ||
|
|
||
| Let's unwrap the key. | ||
| ```cpp Snippet:KeysSample6UnwrapKey | ||
| auto unwrapResult | ||
| = cryptoClient.UnwrapKey(KeyWrapAlgorithm::RsaOaep, wrapResult.EncryptedKey).Value; | ||
| std::cout << " - Decrypted data using the algorithm " << unwrapResult.Algorithm.ToString() | ||
| << ", with key " << unwrapResult.KeyId << ". The resulting decrypted data is: " | ||
| << Azure::Core::Convert::Base64Encode(unwrapResult.Key) << std::endl; | ||
| ``` | ||
|
|
||
| ## Deleting a key | ||
|
|
||
| The cloud RSA key is no longer needed, so we need to delete it from the Key Vault. | ||
|
|
||
| ```cpp Snippet:KeysSample1DeleteKey | ||
| DeleteKeyOperation operation = keyClient.StartDeleteKey(rsaKeyName); | ||
| ``` | ||
|
|
||
| ## Purging a deleted key | ||
|
|
||
| If the Azure Key Vault is soft delete-enabled and you want to permanently delete the key before its `ScheduledPurgeDate`, | ||
| the deleted key needs to be purged. Before it can be purged, you need to wait until the key is fully deleted. | ||
|
|
||
| ```cpp Snippet:KeysSample1PurgeKey | ||
| // You only need to wait for completion if you want to purge or recover the key. | ||
| operation.PollUntilDone(std::chrono::milliseconds(2000)); | ||
|
|
||
| keyClient.PurgeDeletedKey(rsaKeyName); | ||
| ``` | ||
|
|
||
| ## Source | ||
|
|
||
| - [sample6_wrap_unwrap.cpp](https://github.com/Azure/azure-sdk-for-cpp/blob/main/sdk/keyvault/azure-security-keyvault-keys/test/samples/sample6-wrap-unwrap/sample6_wrap_unwrap.cpp) | ||
|
|
||
| [defaultazurecredential]: https://github.com/Azure/azure-sdk-for-cpp/blob/main/sdk/identity/azure-identity/README.md |
108 changes: 108 additions & 0 deletions
108
sdk/keyvault/azure-security-keyvault-keys/samples/sample7_key_rotation.md
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| # Creating, updating rotation policy, and rotating keys | ||
|
|
||
| This sample demonstrates how to create a key, update the rotation policy of the key, rotate the key in Azure Key Vault. | ||
| To get started, you'll need a URI to an Azure Key Vault. See the [README](https://github.com/Azure/azure-sdk-for-cpp/blob/main/sdk/keyvault/azure-security-keyvault-keys/README.md) for links and instructions. | ||
|
|
||
| ## Creating a KeyClient | ||
|
|
||
| To create a new `KeyClient` to create, get, update, or delete keys, you need the endpoint to an Azure Key Vault and credentials. | ||
|
|
||
| Key Vault Keys client for C++ currently supports the `ClientSecretCredential` for authenticating. | ||
|
|
||
| In the sample below, you can create a credential by setting the Tenant ID, Client ID and client secret as environment variables. | ||
|
|
||
| ```cpp Snippet:KeysSample7CreateCredential | ||
| auto tenantId = std::getenv("AZURE_TENANT_ID"); | ||
| auto clientId = std::getenv("AZURE_CLIENT_ID"); | ||
| auto clientSecret = std::getenv("AZURE_CLIENT_SECRET"); | ||
| auto credential = std::make_shared<Azure::Identity::ClientSecretCredential>(tenantId, clientId, clientSecret); | ||
| ``` | ||
|
|
||
| Then, in the sample below, you can set `keyVaultUrl` based on an environment variable, configuration setting, or any way that works for your application. | ||
|
|
||
| ```cpp Snippet:KeysSample7KeyClient | ||
| KeyClient keyClient(std::getenv("AZURE_KEYVAULT_URL"), credential); | ||
| ``` | ||
|
|
||
| ## Creating a key | ||
|
|
||
| Let's create an EC key. | ||
| If the key already exists in the Azure Key Vault, then a new version of the key is created. | ||
|
|
||
| ```cpp Snippet:KeysSample7CreateKey | ||
| auto keyName = "RotateKey-" + Azure::Core::Uuid::CreateUuid().ToString(); | ||
| auto createKeyResponse = keyClient.CreateEcKey(CreateEcKeyOptions(keyName)); | ||
|
|
||
| std::cout << "Created key " << createKeyResponse.Value.Name() << "with id " | ||
| << createKeyResponse.Value.Id() << " and version " | ||
| << createKeyResponse.Value.Properties.Version << std::endl; | ||
| ``` | ||
|
|
||
| ## Create the key rotation policy | ||
|
|
||
| Next we will define the key rotation policy as needed. | ||
|
|
||
| ```cpp Snippet:KeysSample7DefinePolicy | ||
| KeyRotationPolicy policy; | ||
|
|
||
| LifetimeActionsType lifetimeAction1; | ||
| lifetimeAction1.Trigger.TimeBeforeExpiry = "P18M"; | ||
| lifetimeAction1.Action = LifetimeActionType::Notify; | ||
| policy.LifetimeActions.emplace_back(lifetimeAction1); | ||
|
|
||
| LifetimeActionsType lifetimeAction2; | ||
| lifetimeAction2.Action = LifetimeActionType::Rotate; | ||
| lifetimeAction2.Trigger.TimeBeforeExpiry = "P30D"; | ||
| policy.LifetimeActions.emplace_back(lifetimeAction2); | ||
|
|
||
| policy.Attributes.ExpiryTime = "P48M"; | ||
| ``` | ||
|
|
||
| ## Updating key properties | ||
|
|
||
| Now we will update the key with the new rotation policy. | ||
|
|
||
| ```cpp Snippet:KeysSample7UpdateKeyRotation | ||
| auto putPolicy = keyClient.UpdateKeyRotationPolicy(keyName, policy).Value; | ||
|
|
||
| std::cout << "Updated rotation policy " << putPolicy.Id << " for key " | ||
| << createKeyResponse.Value.Name() << std::endl; | ||
| ``` | ||
|
|
||
| ## Calling Rotate and checking the result | ||
|
|
||
| Next we will rotate the key and check the result of the api call. | ||
| ```cpp Snippet:KeysSample7RotateKey | ||
| auto originalKey = keyClient.GetKey(keyName); | ||
| auto rotatedKey = keyClient.RotateKey(keyName); | ||
|
|
||
| std::cout << "Rotated key " << originalKey.Value.Name() << std::endl | ||
| << "Original version " << originalKey.Value.Properties.Version << std::endl | ||
| << "New Version " << rotatedKey.Value.Properties.Version << std::endl; | ||
| ``` | ||
|
|
||
| ## Deleting a key | ||
|
|
||
| The cloud RSA key is no longer needed, so we need to delete it from the Key Vault. | ||
|
|
||
| ```cpp Snippet:KeysSample1DeleteKey | ||
| DeleteKeyOperation operation = keyClient.StartDeleteKey(rsaKeyName); | ||
| ``` | ||
|
|
||
| ## Purging a deleted key | ||
|
|
||
| If the Azure Key Vault is soft delete-enabled and you want to permanently delete the key before its `ScheduledPurgeDate`, | ||
| the deleted key needs to be purged. Before it can be purged, you need to wait until the key is fully deleted. | ||
|
|
||
| ```cpp Snippet:KeysSample1PurgeKey | ||
| // You only need to wait for completion if you want to purge or recover the key. | ||
| operation.PollUntilDone(std::chrono::milliseconds(2000)); | ||
|
|
||
| keyClient.PurgeDeletedKey(rsaKeyName); | ||
| ``` | ||
|
|
||
| ## Source | ||
|
|
||
| - [sample7_key_rotation.cpp](https://github.com/Azure/azure-sdk-for-cpp/blob/main/sdk/keyvault/azure-security-keyvault-keys/test/samples/sample7-key-rotation/sample7_key_rotation.cpp) | ||
|
|
||
| [defaultazurecredential]: https://github.com/Azure/azure-sdk-for-cpp/blob/main/sdk/identity/azure-identity/README.md |
This file contains hidden or 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
16 changes: 16 additions & 0 deletions
16
sdk/keyvault/azure-security-keyvault-keys/test/samples/sample7-key-rotation/CMakeLists.txt
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| # Copyright (c) Microsoft Corporation. All rights reserved. | ||
| # SPDX-License-Identifier: MIT | ||
|
|
||
| cmake_minimum_required (VERSION 3.13) | ||
|
|
||
| project (sample7-key-rotation LANGUAGES CXX) | ||
| set(CMAKE_CXX_STANDARD 14) | ||
| set(CMAKE_CXX_STANDARD_REQUIRED True) | ||
|
|
||
| add_executable ( | ||
| sample7-key-rotation | ||
| sample7_key_rotation.cpp | ||
| ) | ||
| create_per_service_target_build_for_sample(keyvault sample7-key-rotation) | ||
|
|
||
| target_link_libraries(sample7-key-rotation PRIVATE azure-security-keyvault-keys azure-identity get-env-helper) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.