Comments (3)
Yes, you can just pass the network stream object directly to the method. Use of memory stream in the docs is just as an example.
from pgpcore.
I ran into a similar problem today and I have found at least one case in which a non-seekable input stream is not working.
I was using Azure Blob storage and was using a Azure.Storage.NonDisposingStream, which I was trying to Encrypt & Sign using EncryptStreamAndSignAsync
.
This resulted in the following exception:
System.NotSupportedException: Specified method is not supported.
at Azure.Core.Pipeline.RetriableStream+RetriableStreamImpl.get_Length (Azure.Storage.Blobs, Version=12.19.1.0, Culture=neutral, PublicKeyToken=92742159e12e44c8)
at Azure.Storage.NonDisposingStream.get_Length (Azure.Storage.Blobs, Version=12.19.1.0, Culture=neutral, PublicKeyToken=92742159e12e44c8)
at PgpCore.PGP.ChainLiteralStreamOut (PgpCore, Version=6.0.0.0, Culture=neutral, PublicKeyToken=e84be4b896fe5158)
at PgpCore.PGP+<OutputEncryptedAsync>d__36.MoveNext (PgpCore, Version=6.0.0.0, Culture=neutral, PublicKeyToken=e84be4b896fe5158)
...
at PgpCore.PGP+<EncryptAndSignAsync>d__101.MoveNext (PgpCore, Version=6.0.0.0, Culture=neutral, PublicKeyToken=e84be4b896fe5158)
...
at PgpCore.PGP+<EncryptStreamAndSignAsync>d__104.MoveNext (PgpCore, Version=6.0.0.0, Culture=neutral, PublicKeyToken=e84be4b896fe5158)
...
Some streams are not seakable and can throw an Exception while checking for the Length of the stream. This is documented by Microsoft, see Stream.Length.
I have worked around this issue by copying the data from my Blob storage stream to a MemoryStream before passing it to PGPCore.
using var seekableInputStream = new MemoryStream();
await inputStream.CopyToAsync(seekableInputStream);
await pgp.EncryptStreamAndSignAsync(inputStream, outputStream);
Not sure of more changes are needed, but looking at the PGPCore code, the issue is with the initialization of PGPLiteralDataGenerator using the Length of the input stream, without checking if the input stream CanSeek equals true.
Looking at bouncycastle documentation, there should also be an option to initialize without specifiling the length of the input stream.
https://javadoc.io/static/org.bouncycastle/bcpg-jdk15on/1.64/index.html?org/bouncycastle/openpgp/PGPLiteralDataGenerator.html
from pgpcore.
Thanks for doing some initial investigation on this. I seem to remember that there's some other points where we need a seekable stream but I'll take a look when I get a chance to see if changes to PGPLiteralDataGenerator is enough to resolve it.
from pgpcore.
Related Issues (20)
- Nuget publishing? HOT 1
- SignStreamAsync without armor results in closed outputstream HOT 1
- Does this library support Ascii Armor? If so, please provide a sample code HOT 1
- Getting error with Verify HOT 1
- SonarQube scanner java error HOT 1
- PGPCore Error: Org.BouncyCastle.Bcpg.OpenPgp.PgpSecretKeyRing found where PgpPublicKeyRing expected HOT 1
- Verified file has extra characters. HOT 10
- error in BouncyCastle.Utilities.Strings.ToUtf8ByteArray HOT 5
- hash algorithm constant mismatch with bouncy castle when sign
- Generate Key example command doesn't work as provided
- Verify methods should also verify clear signed files
- Add a dethatched sign method
- Add multiple Private Keys to Encryption keys HOT 11
- DecryptStream is very slow HOT 1
- Provide FileName associated with the encrypted data stream HOT 1
- Cannot select non-default PublicKeyAlgorithmTag HOT 2
- VerifyClearAsync string,string overload does not update output variable HOT 2
- Could not find any signing keys in keyring HOT 2
- Publish latest release to NuGet HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pgpcore.