PGP Encrypted Stream For Messages

256 views
Skip to first unread message

Jonny Wilson

unread,
Oct 1, 2013, 12:03:00 PM10/1/13
to didisof...@googlegroups.com
Good afternoon,

Is it possible (I couldn't see it in the examples folder) to take an encrypted PGP message and analyse is as you can for an archive to identify the keys in that cipher block?

I can see the inspect.ListEncryptionKeyIds method has a overload to take an OpenPGP encrypted stream, but how do I create this from the encrypted PGP message?

Thank you.

didisoft

unread,
Oct 1, 2013, 12:35:15 PM10/1/13
to didisof...@googlegroups.com
Hi Jonny,

Do you have the OpenPGP message as a String?

Best Regards,
Peter Kalef
DidiSoft Technical Support

Jonny Wilson

unread,
Oct 1, 2013, 12:50:06 PM10/1/13
to didisof...@googlegroups.com
Yes, to clarify, I am sent and encrypted message by email:

-----BEGIN PGP MESSAGE-----
Version: DidiSoft OpenPGP Library for .NET / BCPG C# v1.7.5011.21705
...encrypted message...
-----END PGP MESSAGE-----

I copy this to my clipboard and I have a method to allow users to decrypt the message and show it in a notepad screen. This is fine. It works.
It would be nice to allow users to see who else can decrypt this message (by allowing me to read a list of key ID's and lookup the usernames) the message is encrypted to.

I hope this makes sense :)

didisoft

unread,
Oct 1, 2013, 3:34:45 PM10/1/13
to didisof...@googlegroups.com
Hi Jonny,

You can use the methods of the PGPInspectLib class that require a Stream parameter.

ASCII armored messages can easily be converted to a Stream with a code like this:

string message = ...
Stream encryptedStream = new MemoryStream(System.Text.ASCIIEncoding.ASCII.GetBytes(message));

Jonny Wilson

unread,
Oct 2, 2013, 4:45:45 AM10/2/13
to didisof...@googlegroups.com
Thank Peter,

I tried that, but I get the error:
"The supplied data is not a valid OpenPGP message"

Inner Exception: {"unknown object in stream 28"}

My method:

            public static List<KeyPairInformation> GetKeysFromPgpMessage(string message)
            {
                var encryptionKeys = new List<KeyPairInformation>(); // create a return list
                var inspector = new PGPInspectLib(); // instantiate the inspector

                Stream encryptedStream = new MemoryStream(System.Text.ASCIIEncoding.ASCII.GetBytes(message)); // get the stream

                if (inspector.IsPublicKeyEncrypted(encryptedStream)) // check it is a valid stream
                {
                    long[] encryptionKeyIds = inspector.ListEncryptionKeyIds(encryptedStream); // pass stream to retrieve list of key id's // throws here.

                    foreach (long keyId in encryptionKeyIds)
                        encryptionKeys.Add(KeyManagement.GetKeyFromKeyId(keyId)); // populate return list with Key Information
                }

                return encryptionKeys;
            }


Thanks again for your help - I hope I'm not being stupid and wasting your time?!

didisoft

unread,
Oct 2, 2013, 4:53:41 AM10/2/13
to didisof...@googlegroups.com
Hi Jonny,

Is it possible to send us a sample encrypted message to support(at)didisoft.com ?

Jonny Wilson

unread,
Oct 2, 2013, 5:12:36 AM10/2/13
to didisof...@googlegroups.com
Thank you.
I've just sent it, subject: "PGP Message (Support Query)"

didisoft

unread,
Oct 2, 2013, 9:11:57 AM10/2/13
to didisof...@googlegroups.com
Hi Jonny,

The updated version was officially released as version 1.7.7.13.

Jonny Wilson

unread,
Oct 2, 2013, 10:33:23 AM10/2/13
to didisof...@googlegroups.com
Thank you! :)
Reply all
Reply to author
Forward
0 new messages