Skip to content
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

fix issue #18808 about Storage Blob Cryptography #20977

Merged
merged 1 commit into from
Jul 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions sdk/storage/azure-storage-blob-cryptography/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ Unstructured data is data that does not adhere to a particular data model or
definition, such as text or binary data.
This package supports client side encryption for blob storage.

[Source code][source] | [API reference documentation][docs] | [REST API documentation][rest_docs] | [Product documentation][product_docs] | [Samples][samples]

## Getting started

### Prerequisites
Expand Down Expand Up @@ -120,7 +122,7 @@ The following sections provide several code snippets covering some of the most c

Create an `EncryptedBlobClient` using a `BlobClient`. `BlobClient` construction is explained in the `azure-storage-blob` README.

<!-- embedme ./src/samples/java/com/azure/storage/blob/specialized/cryptography/ReadmeSamples.java#L42-L46 -->
<!-- embedme ./src/samples/java/com/azure/storage/blob/specialized/cryptography/ReadmeSamples.java#L44-L48 -->
```java
EncryptedBlobClient client = new EncryptedBlobClientBuilder()
.key(key, keyWrapAlgorithm)
Expand All @@ -133,18 +135,20 @@ EncryptedBlobClient client = new EncryptedBlobClientBuilder()

Create a `BlobServiceClient` using a connection string.

<!-- embedme ./src/samples/java/com/azure/storage/blob/specialized/cryptography/ReadmeSamples.java#L50-L54 -->
<!-- embedme ./src/samples/java/com/azure/storage/blob/specialized/cryptography/ReadmeSamples.java#L52-L58 -->
```java
EncryptedBlobClient client = new EncryptedBlobClientBuilder()
.key(key, keyWrapAlgorithm)
.keyResolver(keyResolver)
.connectionString(connectionString)
.containerName(containerName)
.blobName(blobName)
.buildEncryptedBlobClient();
```

### Use a local `KeyEncryptionKey`

<!-- embedme ./src/samples/java/com/azure/storage/blob/specialized/cryptography/ReadmeSamples.java#L58-L67 -->
<!-- embedme ./src/samples/java/com/azure/storage/blob/specialized/cryptography/ReadmeSamples.java#L62-L73 -->
```java
JsonWebKey localKey = JsonWebKey.fromAes(new SecretKeySpec(keyBytes, secretKeyAlgorithm),
Arrays.asList(KeyOperation.WRAP_KEY, KeyOperation.UNWRAP_KEY))
Expand All @@ -155,12 +159,14 @@ AsyncKeyEncryptionKey akek = new KeyEncryptionKeyClientBuilder()
EncryptedBlobClient client = new EncryptedBlobClientBuilder()
.key(akek, keyWrapAlgorithm)
.connectionString(connectionString)
.containerName(containerName)
.blobName(blobName)
.buildEncryptedBlobClient();
```

### Use a `KeyVaultKey`

<!-- embedme ./src/samples/java/com/azure/storage/blob/specialized/cryptography/ReadmeSamples.java#L71-L86 -->
<!-- embedme ./src/samples/java/com/azure/storage/blob/specialized/cryptography/ReadmeSamples.java#L77-L94 -->
```java
KeyClient keyClient = new KeyClientBuilder()
.vaultUrl(keyVaultUrl)
Expand All @@ -177,6 +183,8 @@ AsyncKeyEncryptionKey akek = new KeyEncryptionKeyClientBuilder()
EncryptedBlobClient client = new EncryptedBlobClientBuilder()
.key(akek, keyWrapAlgorithm)
.connectionString(connectionString)
.containerName(containerName)
.blobName(blobName)
.buildEncryptedBlobClient();
```

Expand Down Expand Up @@ -214,3 +222,8 @@ This project has adopted the [Microsoft Open Source Code of Conduct](https://ope
[storage_account_create_cli]: https://docs.microsoft.com/azure/storage/common/storage-quickstart-create-account?tabs=azure-cli
[storage_account_create_portal]: https://docs.microsoft.com/azure/storage/common/storage-quickstart-create-account?tabs=azure-portal
[sas_token]: https://docs.microsoft.com/azure/storage/common/storage-dotnet-shared-access-signature-part-1
[source]: https://github.com/Azure/azure-sdk-for-java/tree/master/sdk/storage/azure-storage-blob-cryptography/src/main/java
[docs]: https://azure.github.io/azure-sdk-for-java/
[rest_docs]: https://docs.microsoft.com/rest/api/storageservices/blob-service-rest-api
[product_docs]: https://docs.microsoft.com/azure/storage/blobs/storage-blobs-overview
[samples]: https://github.com/Azure/azure-sdk-for-java/tree/master/sdk/storage/azure-storage-blob-cryptography/src/samples
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ public class ReadmeSamples {
private TokenCredential tokenCredential;
private String keyVaultUrl;
private String keyName;
private String containerName;
private String blobName;

public void getEncryptedBlobClientBlobClient() {
EncryptedBlobClient client = new EncryptedBlobClientBuilder()
Expand All @@ -51,6 +53,8 @@ public void getEncryptedBlobClient() {
.key(key, keyWrapAlgorithm)
.keyResolver(keyResolver)
.connectionString(connectionString)
.containerName(containerName)
.blobName(blobName)
.buildEncryptedBlobClient();
}

Expand All @@ -64,6 +68,8 @@ public void getClientLocalKey() {
EncryptedBlobClient client = new EncryptedBlobClientBuilder()
.key(akek, keyWrapAlgorithm)
.connectionString(connectionString)
.containerName(containerName)
.blobName(blobName)
.buildEncryptedBlobClient();
}

Expand All @@ -83,6 +89,8 @@ public void getClientKeyVaultKey() {
EncryptedBlobClient client = new EncryptedBlobClientBuilder()
.key(akek, keyWrapAlgorithm)
.connectionString(connectionString)
.containerName(containerName)
.blobName(blobName)
.buildEncryptedBlobClient();
}

Expand Down