Is there a way to decrypt an encrypted data on fly while uploading it on Azure blob storage using Azure Key Vault?

Sharma, Arpana 51 Reputation points
2023-01-20T21:13:17.1433333+00:00

We have a scenerio in our case:

  1. A file is encrypted using the consumer's public key over a physical device.
  2. That encrypted file, in decrypted format, is to be stored over Azure blob storage.
  3. The consumer's private key is already stored in a Azure key vault. Problem statement: Is there a way (in step 2) to decrypt the encrypted data on the fly while uploading to the Azure Blob Storage using Python. Any link/refernce would be appreciated.
Azure Key Vault
Azure Key Vault
An Azure service that is used to manage and protect cryptographic keys and other secrets used by cloud apps and services.
1,112 questions
Azure Blob Storage
Azure Blob Storage
An Azure service that stores unstructured data in the cloud as blobs.
2,427 questions
{count} votes

Accepted answer
  1. SanthiSwaroopNaikBukke-4908 595 Reputation points
    2023-01-20T21:17:17.9333333+00:00

    Yes, it is possible to decrypt the encrypted data on the fly while uploading it to Azure Blob Storage using Python. One way to accomplish this is to use the Azure Key Vault to retrieve the consumer's private key, and then use that key to decrypt the file before uploading it to Azure Blob Storage.

    Here is an example of how you can decrypt the data on the fly using Python and the Azure Key Vault library:

    Copy code
    import azure.keyvault as kv
    from azure.identity import DefaultAzureCredential
    from azure.storage.blob import BlobServiceClient
    
    # Connect to Azure Key Vault and retrieve private key
    credential = DefaultAzureCredential()
    client = kv.KeyVaultClient(credential)
    private_key = client.get_secret("<key-vault-name>", "<secret-name>").value
    
    # Decrypt file using private key
    decrypted_file = some_decryption_function(encrypted_file, private_key)
    
    # Upload decrypted file to Azure Blob Storage
    blob_service_client = BlobServiceClient(<connection_string>)
    blob_client = blob_service_client.get_blob_client(<container_name>, <blob_name>)
    blob_client.upload_blob(decrypted_file)
    

    You need to replace the connection string, container name and blob name with the actual values and use a decryption function that fits the encryption algorithm and key that you used. The above example uses the azure-identity and azure-keyvault-secrets package to authenticate and connect to the key vault, and azure-storage-blob package for uploading the decrypted data to Azure Blob storage.

    0 comments No comments

0 additional answers

Sort by: Most helpful