Я хочу расшифровать большие двоичные объекты, зашифрованные с помощью шифрования на стороне клиента, с помощью следующего кода C#, который выполняется в рабочей среде и соответствует примерам Microsoft C#:
public static IServiceCollection AddEncryptedFileStorage(this IServiceCollection services, string configurationSectionName) where T : class, IFileStorage
{
string clientName = configurationSectionName;
services.AddAzureClients(clientBuilder =>
{
clientBuilder.AddClient((options, credential, serviceProvider) =>
{
var configuration = serviceProvider.GetRequiredService();
var configurationSection = configuration.GetSection(configurationSectionName);
var storageAccountUri = FileStorageHelper.GetStorageAccountUri(configurationSection.GetRequiredValue("StorageAccountName"));
string encryptionKeyId = configurationSection.GetValue("EncryptionKeyId")!;
var keyClient = serviceProvider.GetRequiredService();
KeyVaultKey key = keyClient.GetKey(encryptionKeyId, cancellationToken: CancellationToken.None);
var encryptionOptions = new ClientSideEncryptionOptions(ClientSideEncryptionVersion.V2_0)
{
KeyEncryptionKey = new CryptographyClient(key.Id, credential),
KeyResolver = new KeyResolver(credential),
KeyWrapAlgorithm = "RSA-OAEP"
};
var blobClientOptions = new SpecializedBlobClientOptions
{
ClientSideEncryption = encryptionOptions,
Retry = { Delay = options.Retry.NetworkTimeout, MaxRetries = options.Retry.MaxRetries }
};
return new BlobServiceClient(storageAccountUri, credential, blobClientOptions);
}).WithName(clientName);
});
services.TryAddSingleton(typeof(T), sp => FileStorageFactory(sp, clientName, configurationSectionName));
services.AddHealthChecks().AddBlobStorage(clientName);
return services;
}
Следуя документации Microsoft Python, я попытался запустить следующий код, который печатает данные, если параметры шифрования не установлены, но в противном случае выдает эту ошибку:
HttpResponseError: Decryption failed.
File /local_disk0/.ephemeral_nfs/envs/pythonEnv-c5de91e5-86a9-4892-ae41-922218e4545e/lib/python3.10/site-packages/azure/storage/blob/_download.py:70, in process_content(data, start_offset, end_offset, encryption)
69 try:
---> 70 return decrypt_blob(
71 encryption.get("required") or False,
72 encryption.get("key"),
73 encryption.get("resolver"),
74 content,
75 start_offset,
76 end_offset,
77 data.response.headers,
78 )
79 except Exception as error:
File /local_disk0/.ephemeral_nfs/envs/pythonEnv-c5de91e5-86a9-4892-ae41-922218e4545e/lib/python3.10/site-packages/azure/storage/blob/_encryption.py:905, in decrypt_blob(require_encryption, key_encryption_key, key_resolver, content, start_offset, end_offset, response_headers)
903 raise ValueError('Specified encryption version is not supported.')
--> 905 content_encryption_key = _validate_and_unwrap_cek(encryption_data, key_encryption_key, key_resolver)
907 if version == _ENCRYPTION_PROTOCOL_V1:
File /local_disk0/.ephemeral_nfs/envs/pythonEnv-c5de91e5-86a9-4892-ae41-922218e4545e/lib/python3.10/site-packages/azure/storage/blob/_encryption.py:658, in _validate_and_unwrap_cek(encryption_data, key_encryption_key, key_resolver)
657 if not hasattr(key_encryption_key, 'get_kid') or not callable(key_encryption_key.get_kid):
--> 658 raise AttributeError(_ERROR_OBJECT_INVALID.format('key encryption key', 'get_kid'))
659 if not hasattr(key_encryption_key, 'unwrap_key') or not callable(key_encryption_key.unwrap_key):
AttributeError: key encryption key does not define a complete interface. Value of get_kid is either missing or invalid.
Таким образом, SDK ожидает, что ключ шифрования ключа будет иметь метод get_kid() (исходный код SDK), но у CryptographyClient SDK такого метода нет.
p>
Сам пробовал реализовать метод get_kid(), но это приводит к другим проблемам, так что, вероятно, это не тот вариант
Я хочу расшифровать большие двоичные объекты, зашифрованные с помощью шифрования на стороне клиента, с помощью следующего кода C#, который выполняется в рабочей среде и соответствует примерам Microsoft C#: [code]public static IServiceCollection AddEncryptedFileStorage(this IServiceCollection services, string configurationSectionName) where T : class, IFileStorage { string clientName = configurationSectionName; services.AddAzureClients(clientBuilder => { clientBuilder.AddClient((options, credential, serviceProvider) => { var configuration = serviceProvider.GetRequiredService(); var configurationSection = configuration.GetSection(configurationSectionName);
var storageAccountUri = FileStorageHelper.GetStorageAccountUri(configurationSection.GetRequiredValue("StorageAccountName")); string encryptionKeyId = configurationSection.GetValue("EncryptionKeyId")!;
var keyClient = serviceProvider.GetRequiredService();
var encryptionOptions = new ClientSideEncryptionOptions(ClientSideEncryptionVersion.V2_0) { KeyEncryptionKey = new CryptographyClient(key.Id, credential), KeyResolver = new KeyResolver(credential), KeyWrapAlgorithm = "RSA-OAEP" };
var blobClientOptions = new SpecializedBlobClientOptions { ClientSideEncryption = encryptionOptions, Retry = { Delay = options.Retry.NetworkTimeout, MaxRetries = options.Retry.MaxRetries } };
return services; } [/code] Следуя документации Microsoft Python, я попытался запустить следующий код, который печатает данные, если параметры шифрования не установлены, но в противном случае выдает эту ошибку: [code]HttpResponseError: Decryption failed. File /local_disk0/.ephemeral_nfs/envs/pythonEnv-c5de91e5-86a9-4892-ae41-922218e4545e/lib/python3.10/site-packages/azure/storage/blob/_download.py:70, in process_content(data, start_offset, end_offset, encryption) 69 try: ---> 70 return decrypt_blob( 71 encryption.get("required") or False, 72 encryption.get("key"), 73 encryption.get("resolver"), 74 content, 75 start_offset, 76 end_offset, 77 data.response.headers, 78 ) 79 except Exception as error: File /local_disk0/.ephemeral_nfs/envs/pythonEnv-c5de91e5-86a9-4892-ae41-922218e4545e/lib/python3.10/site-packages/azure/storage/blob/_encryption.py:905, in decrypt_blob(require_encryption, key_encryption_key, key_resolver, content, start_offset, end_offset, response_headers) 903 raise ValueError('Specified encryption version is not supported.') --> 905 content_encryption_key = _validate_and_unwrap_cek(encryption_data, key_encryption_key, key_resolver) 907 if version == _ENCRYPTION_PROTOCOL_V1: File /local_disk0/.ephemeral_nfs/envs/pythonEnv-c5de91e5-86a9-4892-ae41-922218e4545e/lib/python3.10/site-packages/azure/storage/blob/_encryption.py:658, in _validate_and_unwrap_cek(encryption_data, key_encryption_key, key_resolver) 657 if not hasattr(key_encryption_key, 'get_kid') or not callable(key_encryption_key.get_kid): --> 658 raise AttributeError(_ERROR_OBJECT_INVALID.format('key encryption key', 'get_kid')) 659 if not hasattr(key_encryption_key, 'unwrap_key') or not callable(key_encryption_key.unwrap_key): AttributeError: key encryption key does not define a complete interface. Value of get_kid is either missing or invalid. [/code] [code]from azure.storage.blob import BlobServiceClient from azure.identity import DefaultAzureCredential, DeviceCodeCredential from azure.keyvault.keys import KeyClient from azure.keyvault.keys.crypto import CryptographyClient from azure.keyvault.keys.crypto import KeyWrapAlgorithm from azure.core.exceptions import ResourceNotFoundError
blob_data [/code] Таким образом, SDK ожидает, что ключ шифрования ключа будет иметь метод get_kid() (исходный код SDK), но у CryptographyClient SDK такого метода нет. p> Сам пробовал реализовать метод get_kid(), но это приводит к другим проблемам, так что, вероятно, это не тот вариант