Azure Blob 动态加密
In motion encryption of Azure Blobs
我有一个场景,我需要从一个存储帐户中取出一个 blob(大小超过数 GB)并复制并加密它并将其放入另一个 blob 存储帐户中。看起来我可以通过设置 BlobEncryptionPolicy 并执行 StartCopyAsync 来做到这一点。但是,这需要 Key Vault 访问权限,并且将下载此加密 blob 的系统将无权访问该保管库。我们也无权访问收件人的私钥(因为它是他们的,而不是我们的),所以我们不能只将他们的 .pfx 加载到我们的保管库中。
关闭 table 我不确定还有什么其他选择:
1. 将 blob 下载到云服务的文件系统(或者可能是 azure 文件存储帐户)并对其进行加密。
2. 将加密后的文件上传到目标blob存储账户。
3. 从共享中删除加密文件。
在这种情况下还有其他可行的方法吗?
Are there other approaches that may work in this case?
据我所知,azure storage有两个加密。
一个是 server-side encryption,Azure 存储会在保存到存储之前自动加密您的数据,并在检索之前自动解密。加密、解密、密钥管理对用户完全透明
通过这种方式,Azure会在上传到存储服务器时加密你的数据。 当用户想要访问数据时,它会解密数据。
您可以直接在门户中启用它,如下所示:
另一种是客户端加密,我们可以使用天蓝色密钥值或本地密钥值来加密数据。
所以如果我们想使用客户端加密,我们需要从 blob 下载文件然后加密并上传到另一个存储帐户。
This is the client-side Encryption without use azure key-value way.
我们可以创建一个本地rsa密钥来加密它,然后您可以将这个rsa密钥存储在本地。
如果你想从 blob 中解密加密的内容,你可以使用 rsa 密钥。
更多详细信息,您可以参考以下示例:
LocalResolver.cs(用于存放ikey)
public class LocalResolver : IKeyResolver
{
private Dictionary<string, IKey> keys = new Dictionary<string, IKey>();
public void Add(IKey key)
{
keys[key.Kid] = key;
}
public async Task<IKey> ResolveKeyAsync(string kid, CancellationToken token)
{
IKey result;
keys.TryGetValue(kid, out result);
return await Task.FromResult(result);
}
}
上传加密 blob 并下载解密 blob:
static void Main(string[] args)
{
Console.WriteLine("Blob encryption sample");
// Retrieve storage account information from connection string
// How to create a storage connection string - https://azure.microsoft.com/en-us/documentation/articles/storage-configure-connection-string/
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
"DefaultEndpointsProtocol=https;AccountName=brandofirststorage;AccountKey=4j8EjQzNtkzQ22Xp3NZcxvJz/+PUOOOQRTSZ9TieQg1lYM6eBCDpKoJgMcNWoG6p1GjMQhkYrxPKRBralzQoZA==;EndpointSuffix=core.windows.net");
CloudBlobClient client = storageAccount.CreateCloudBlobClient();
CloudBlobContainer container = client.GetContainerReference("example");
container.CreateIfNotExists();
int size = 5 * 1024 * 1024;
byte[] buffer = new byte[size];
Random rand = new Random();
rand.NextBytes(buffer);
CloudBlockBlob blob = container.GetBlockBlobReference("test");
// Create the IKey used for encryption.
RsaKey key = new RsaKey("private:key1");
// Create the encryption policy to be used for upload.
BlobEncryptionPolicy uploadPolicy = new BlobEncryptionPolicy(key, null);
// Set the encryption policy on the request options.
BlobRequestOptions uploadOptions = new BlobRequestOptions() { EncryptionPolicy = uploadPolicy };
Console.WriteLine("Uploading the encrypted blob.");
// Upload the encrypted contents to the blob.
using (MemoryStream stream = new MemoryStream(buffer))
{
blob.UploadFromStream(stream, size, null, uploadOptions, null);
}
// Download the encrypted blob.
// For downloads, a resolver can be set up that will help pick the key based on the key id.
LocalResolver resolver = new LocalResolver();
resolver.Add(key);
BlobEncryptionPolicy downloadPolicy = new BlobEncryptionPolicy(null, resolver);
// Set the decryption policy on the request options.
BlobRequestOptions downloadOptions = new BlobRequestOptions() { EncryptionPolicy = downloadPolicy };
Console.WriteLine("Downloading the encrypted blob.");
// Download and decrypt the encrypted contents from the blob.
using (MemoryStream outputStream = new MemoryStream())
{
blob.DownloadToStream(outputStream, null, downloadOptions, null);
}
Console.WriteLine("Press enter key to exit");
Console.ReadLine();
}
此外,复制 blob 操作只是在服务器端将字节从源复制到目标。所以它不会在服务器复制文件时对其进行加密。
我有一个场景,我需要从一个存储帐户中取出一个 blob(大小超过数 GB)并复制并加密它并将其放入另一个 blob 存储帐户中。看起来我可以通过设置 BlobEncryptionPolicy 并执行 StartCopyAsync 来做到这一点。但是,这需要 Key Vault 访问权限,并且将下载此加密 blob 的系统将无权访问该保管库。我们也无权访问收件人的私钥(因为它是他们的,而不是我们的),所以我们不能只将他们的 .pfx 加载到我们的保管库中。
关闭 table 我不确定还有什么其他选择: 1. 将 blob 下载到云服务的文件系统(或者可能是 azure 文件存储帐户)并对其进行加密。 2. 将加密后的文件上传到目标blob存储账户。 3. 从共享中删除加密文件。
在这种情况下还有其他可行的方法吗?
Are there other approaches that may work in this case?
据我所知,azure storage有两个加密。
一个是 server-side encryption,Azure 存储会在保存到存储之前自动加密您的数据,并在检索之前自动解密。加密、解密、密钥管理对用户完全透明
通过这种方式,Azure会在上传到存储服务器时加密你的数据。 当用户想要访问数据时,它会解密数据。
您可以直接在门户中启用它,如下所示:
另一种是客户端加密,我们可以使用天蓝色密钥值或本地密钥值来加密数据。
所以如果我们想使用客户端加密,我们需要从 blob 下载文件然后加密并上传到另一个存储帐户。
This is the client-side Encryption without use azure key-value way.
我们可以创建一个本地rsa密钥来加密它,然后您可以将这个rsa密钥存储在本地。
如果你想从 blob 中解密加密的内容,你可以使用 rsa 密钥。
更多详细信息,您可以参考以下示例:
LocalResolver.cs(用于存放ikey)
public class LocalResolver : IKeyResolver
{
private Dictionary<string, IKey> keys = new Dictionary<string, IKey>();
public void Add(IKey key)
{
keys[key.Kid] = key;
}
public async Task<IKey> ResolveKeyAsync(string kid, CancellationToken token)
{
IKey result;
keys.TryGetValue(kid, out result);
return await Task.FromResult(result);
}
}
上传加密 blob 并下载解密 blob:
static void Main(string[] args)
{
Console.WriteLine("Blob encryption sample");
// Retrieve storage account information from connection string
// How to create a storage connection string - https://azure.microsoft.com/en-us/documentation/articles/storage-configure-connection-string/
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
"DefaultEndpointsProtocol=https;AccountName=brandofirststorage;AccountKey=4j8EjQzNtkzQ22Xp3NZcxvJz/+PUOOOQRTSZ9TieQg1lYM6eBCDpKoJgMcNWoG6p1GjMQhkYrxPKRBralzQoZA==;EndpointSuffix=core.windows.net");
CloudBlobClient client = storageAccount.CreateCloudBlobClient();
CloudBlobContainer container = client.GetContainerReference("example");
container.CreateIfNotExists();
int size = 5 * 1024 * 1024;
byte[] buffer = new byte[size];
Random rand = new Random();
rand.NextBytes(buffer);
CloudBlockBlob blob = container.GetBlockBlobReference("test");
// Create the IKey used for encryption.
RsaKey key = new RsaKey("private:key1");
// Create the encryption policy to be used for upload.
BlobEncryptionPolicy uploadPolicy = new BlobEncryptionPolicy(key, null);
// Set the encryption policy on the request options.
BlobRequestOptions uploadOptions = new BlobRequestOptions() { EncryptionPolicy = uploadPolicy };
Console.WriteLine("Uploading the encrypted blob.");
// Upload the encrypted contents to the blob.
using (MemoryStream stream = new MemoryStream(buffer))
{
blob.UploadFromStream(stream, size, null, uploadOptions, null);
}
// Download the encrypted blob.
// For downloads, a resolver can be set up that will help pick the key based on the key id.
LocalResolver resolver = new LocalResolver();
resolver.Add(key);
BlobEncryptionPolicy downloadPolicy = new BlobEncryptionPolicy(null, resolver);
// Set the decryption policy on the request options.
BlobRequestOptions downloadOptions = new BlobRequestOptions() { EncryptionPolicy = downloadPolicy };
Console.WriteLine("Downloading the encrypted blob.");
// Download and decrypt the encrypted contents from the blob.
using (MemoryStream outputStream = new MemoryStream())
{
blob.DownloadToStream(outputStream, null, downloadOptions, null);
}
Console.WriteLine("Press enter key to exit");
Console.ReadLine();
}
此外,复制 blob 操作只是在服务器端将字节从源复制到目标。所以它不会在服务器复制文件时对其进行加密。