azure-docs-sdk-java/docs-ref-autogen/com.azure.security.keyvault...

19 строки
8.9 KiB
YAML

### YamlMime:JavaPackage
uid: "com.azure.security.keyvault.keys.cryptography"
fullName: "com.azure.security.keyvault.keys.cryptography"
name: "com.azure.security.keyvault.keys.cryptography"
summary: "[Azure Key Vault][] is a cloud-based service provided by Microsoft Azure that allows users to securely store and manage cryptographic keys used for encrypting and decrypting data.\n\n\n[Azure Key Vault]: https://learn.microsoft.com/azure/key-vault/general/"
classes:
- "com.azure.security.keyvault.keys.cryptography.CryptographyAsyncClient"
- "com.azure.security.keyvault.keys.cryptography.CryptographyClient"
- "com.azure.security.keyvault.keys.cryptography.CryptographyClientBuilder"
- "com.azure.security.keyvault.keys.cryptography.KeyEncryptionKeyAsyncClient"
- "com.azure.security.keyvault.keys.cryptography.KeyEncryptionKeyClient"
- "com.azure.security.keyvault.keys.cryptography.KeyEncryptionKeyClientBuilder"
enums:
- "com.azure.security.keyvault.keys.cryptography.CryptographyServiceVersion"
desc: "[Azure Key Vault][] is a cloud-based service provided by Microsoft Azure that allows users to securely store and manage cryptographic keys used for encrypting and decrypting data. It is a part of Azure Key Vault, which is a cloud-based service for managing cryptographic keys, secrets, and certificates.\n\nThe service supports various cryptographic algorithms and operations, including symmetric and asymmetric encryption, digital signatures, hashing, and random number generation. You can use the service to perform operations like encrypting sensitive data before storing it, decrypting data when needed, signing data to ensure its integrity, and verifying signatures to validate the authenticity of the data.\n\nBy utilizing Azure Key Vault Cryptography service, you benefit from the strong security features provided by Azure Key Vault, such as hardware security modules (HSMs) for key storage and cryptographic operations, access control policies, and audit logging. It helps you protect your sensitive data and comply with industry standards and regulatory requirements.\n\nThe Azure Key Vault Keys Cryptography client library allows developers to interact with the Azure Key Vault service from their applications. The library provides a set of APIs that enable developers to securely encrypt, decrypt, sign, and verify data using cryptographic keys securely stored in Key Vault.\n\n**Key Concepts:**\n\nWhat is a Cryptography Client?\n\nThe cryptography client performs the cryptographic operations locally or calls the Azure Key Vault service depending on how much key information is available locally. It supports encrypting, decrypting, signing, verifying, key wrapping, key unwrapping, and retrieving the configured key. Asynchronous (\\`CryptographyAsyncClient\\`) and synchronous (\\`CryptographyClient\\`) clients exist in the SDK allowing for the selection of a client based on an application's use case.\n\n## Getting Started ##\n\nIn order to interact with the Azure Key Vault service, you will need to create an instance of the <xref uid=\"com.azure.security.keyvault.keys.cryptography.CryptographyClient\" data-throw-if-not-resolved=\"false\" data-raw-source=\"com.azure.security.keyvault.keys.cryptography.CryptographyClient\"></xref> class, a vault url and a credential object.\n\nThe examples shown in this document use a credential object named DefaultAzureCredential for authentication, which is appropriate for most scenarios, including local development and production environments. Additionally, we recommend using a [ managed identity][managed identity] for authentication in production environments. You can find more information on different ways of authenticating and their corresponding credential types in the [ Azure Identity documentation\"][Azure Identity documentation].\n\n**Sample: Construct Synchronous Cryptography Client**\n\nThe following code sample demonstrates the creation of a <xref uid=\"com.azure.security.keyvault.keys.cryptography.CryptographyClient\" data-throw-if-not-resolved=\"false\" data-raw-source=\"com.azure.security.keyvault.keys.cryptography.CryptographyClient\"></xref>, using the <xref uid=\"com.azure.security.keyvault.keys.cryptography.CryptographyClientBuilder\" data-throw-if-not-resolved=\"false\" data-raw-source=\"com.azure.security.keyvault.keys.cryptography.CryptographyClientBuilder\"></xref> to configure it.\n\n```java\nCryptographyClient cryptographyClient = new CryptographyClientBuilder()\n .keyIdentifier(\"<your-key-id>\")\n .credential(new DefaultAzureCredentialBuilder().build())\n .buildClient();\n```\n\n**Sample: Construct Asynchronous Cryptography Client**\n\nThe following code sample demonstrates the creation of a <xref uid=\"com.azure.security.keyvault.keys.cryptography.CryptographyAsyncClient\" data-throw-if-not-resolved=\"false\" data-raw-source=\"com.azure.security.keyvault.keys.cryptography.CryptographyAsyncClient\"></xref>, using the <xref uid=\"com.azure.security.keyvault.keys.cryptography.CryptographyClientBuilder\" data-throw-if-not-resolved=\"false\" data-raw-source=\"com.azure.security.keyvault.keys.cryptography.CryptographyClientBuilder\"></xref> to configure it.\n\n```java\nCryptographyAsyncClient cryptographyAsyncClient = new CryptographyClientBuilder()\n .keyIdentifier(\"<your-key-id>\")\n .credential(new DefaultAzureCredentialBuilder().build())\n .buildAsyncClient();\n```\n\n\n--------------------\n\n## Encrypt Data ##\n\nThe <xref uid=\"com.azure.security.keyvault.keys.cryptography.CryptographyClient\" data-throw-if-not-resolved=\"false\" data-raw-source=\"com.azure.security.keyvault.keys.cryptography.CryptographyClient\"></xref> or <xref uid=\"com.azure.security.keyvault.keys.cryptography.CryptographyAsyncClient\" data-throw-if-not-resolved=\"false\" data-raw-source=\"com.azure.security.keyvault.keys.cryptography.CryptographyAsyncClient\"></xref> can be used to encrypt data.\n\n**Synchronous Code Sample:**\n\nThe following code sample demonstrates how to synchronously encrypt data using the <xref uid=\"com.azure.security.keyvault.keys.cryptography.CryptographyClient.encrypt(com.azure.security.keyvault.keys.cryptography.models.EncryptionAlgorithm,byte[])\" data-throw-if-not-resolved=\"false\" data-raw-source=\"com.azure.security.keyvault.keys.cryptography.CryptographyClient#encrypt(com.azure.security.keyvault.keys.cryptography.models.EncryptionAlgorithm, byte[])\"></xref> API.\n\n```java\nbyte[] plaintext = new byte[100];\n new Random(0x1234567L).nextBytes(plaintext);\n\n EncryptResult encryptResult = cryptographyClient.encrypt(EncryptionAlgorithm.RSA_OAEP, plaintext);\n\n System.out.printf(\"Received encrypted content of length: %d, with algorithm: %s.%n\",\n encryptResult.getCipherText().length, encryptResult.getAlgorithm());\n```\n\n**Note:** For the asynchronous sample, refer to <xref uid=\"com.azure.security.keyvault.keys.cryptography.CryptographyAsyncClient\" data-throw-if-not-resolved=\"false\" data-raw-source=\"com.azure.security.keyvault.keys.cryptography.CryptographyAsyncClient\"></xref>.\n\n\n--------------------\n\n## Decrypt Data ##\n\nThe <xref uid=\"com.azure.security.keyvault.keys.cryptography.CryptographyClient\" data-throw-if-not-resolved=\"false\" data-raw-source=\"com.azure.security.keyvault.keys.cryptography.CryptographyClient\"></xref> or <xref uid=\"com.azure.security.keyvault.keys.cryptography.CryptographyAsyncClient\" data-throw-if-not-resolved=\"false\" data-raw-source=\"com.azure.security.keyvault.keys.cryptography.CryptographyAsyncClient\"></xref> can be used to decrypt data.\n\n**Synchronous Code Sample:**\n\nThe following code sample demonstrates how to synchronously decrypt data using the <xref uid=\"com.azure.security.keyvault.keys.cryptography.CryptographyClient.decrypt(com.azure.security.keyvault.keys.cryptography.models.EncryptionAlgorithm,byte[])\" data-throw-if-not-resolved=\"false\" data-raw-source=\"com.azure.security.keyvault.keys.cryptography.CryptographyClient#decrypt(com.azure.security.keyvault.keys.cryptography.models.EncryptionAlgorithm, byte[])\"></xref> API.\n\n```java\nbyte[] ciphertext = new byte[100];\n new Random(0x1234567L).nextBytes(ciphertext);\n\n DecryptResult decryptResult = cryptographyClient.decrypt(EncryptionAlgorithm.RSA_OAEP, ciphertext);\n\n System.out.printf(\"Received decrypted content of length: %d.%n\", decryptResult.getPlainText().length);\n```\n\n**Note:** For the asynchronous sample, refer to <xref uid=\"com.azure.security.keyvault.keys.cryptography.CryptographyAsyncClient\" data-throw-if-not-resolved=\"false\" data-raw-source=\"com.azure.security.keyvault.keys.cryptography.CryptographyAsyncClient\"></xref>.\n\n\n[Azure Key Vault]: https://learn.microsoft.com/azure/key-vault/general/\n[managed identity]: https://learn.microsoft.com/azure/active-directory/managed-identities-azure-resources/\n[Azure Identity documentation]: https://learn.microsoft.com/java/api/overview/azure/identity-readme?view=azure-java-stable"
metadata: {}
package: "com.azure.security.keyvault.keys.cryptography"
artifact: com.azure:azure-security-keyvault-keys:4.8.7