0

BlobClient.OpenReadAsync() returns non seekable stream. When I pass this stream for PGP decyption it gives me below error message. Is there a way to make the blob stream from seekable. I don't want to download file from blob storage account.

var containerClient =_blobServiceClient.GetBlobContainerClient(sourceContainer);
using var pgpStream = await containerClient.GetBlobClient(blobName).OpenReadAsync();
var privateKeyEncoded = Encoding.UTF8.GetString(Convert.FromBase64String(_options.PrivateKey));
Stream outputStream = new MemoryStream();
var privatekeyStreamEncoded = GenerateStreamFromString(privateKeyEncoded);
var deryptedStream= await pgp.DecryptStreamAsync(pgpStream, outputStream, PgpUtilities.GetDecoderStream(privatekeyStreamEncoded), _options.PassPhrase);

Error:

System.Private.CoreLib: Exception while executing function: DecryptPGPFile. BouncyCastle.Crypto: inputStream must be seek-able (Parameter 'inputStream').
suraj_123
  • 115
  • 13

1 Answers1

0

After doing some research, I found that the error which you are getting is due to this method in the underlying BouncyCastle crypto library.

If you look carefully, there's a comment indicating that the condition isn't needed so, I would recommend raising an issue on BouncyCastle to see if it's still necessary or not.

Coming to your question -

Is there a way to make the blob stream from seekable ?

Unfortunately, currently there is no way to make OpenReadAsync() seekable as, the returned stream is designed to resize its length to accommodate blobs that are updating underneath you. You can also check this issue raised for the same problem in Git memory.

SauravDas-MT
  • 1,224
  • 1
  • 4
  • 10
  • It looks like a bug . I am getting the same error when I pass FileStream as inputStream instead of reading blob. Ca you suggest any other library to decrypt pgp file? – suraj_123 Nov 15 '21 at 05:52
  • 1
    You can use **DownloadToStreamAsync()** for this operation. Check this [answer](https://stackoverflow.com/a/55564118) for reference. If the posted answer helped, you may mark it as the answer by clicking the check mark. Doing so can help other community members. – SauravDas-MT Nov 15 '21 at 06:03
  • I already tried that.I still get the same exception. Stream pgpStream = new MemoryStream(); await containerClient.GetBlobClient(blobName).DownloadToAsync(pgpStream); pgpStream.Position = 0; – suraj_123 Nov 15 '21 at 06:18