none
Unable to download the encrypted blob resource

    Question

  • We have a process that encrypts the files while uploading them to Blob storage. This is how the Upload code looks like:


    RsaKey rKey = new RsaKey("mykey");
    
    BlobEncryptionPolicy encPolicy = new BlobEncryptionPolicy(rKey, null);
    
    BlobRequestOptions uploadReqOptions = new BlobRequestOptions() { EncryptionPolicy = encPolicy };
    
    var fileToUpload = OuterContainer.GetBlockBlobReference(string.Format("{0}", fileName));
    
    fileToUpload.UploadFromStream(stream, stream.Length, null, uploadReqOptions, null);

    Then we have another process that downloads the file. While downloading, I am specifying the same RsaKey but for some reason I am getting below error.

    "Error occurred while decoding OAEP padding"

    This is how the download code looks like:

    RsaKey rKey = new RsaKey("mykey");
    
    BlobEncryptionPolicy encPolicy = new BlobEncryptionPolicy(rKey, null);
    
    BlobRequestOptions downloadReqOptions = new BlobRequestOptions() { EncryptionPolicy = encPolicy };
    
    var fileToDownload = OuterContainer.GetBlockBlobReference(string.Format("{0}", fileName));
    
    using (MemoryStream memoryStream = new MemoryStream())
    {
        fileToDownload.DownloadToStream(memoryStream, null, downloadReqOptions);
    }

    If I try to download the file right after uploading it using the downloadReqOptions, it works fine and i can see the decrypted file. I am thinking the way I am creating the RsaKey at two different places is not working as per my assumption.

    Any help will be highly appreciated.



    • Edited by salpad Wednesday, January 6, 2016 3:07 PM
    Wednesday, January 6, 2016 3:00 PM

All replies