0

I am working on a project that requires the basic encryption/decryption of a message. I generated private/public keys with my email and no password. The pgp public key as well as the private key, appear to be in the following format (appears to be base64_encoded):

-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: BCPG C# v1.6.1.0

rwd3434f...key..4d44edw4
-----END PGP PUBLIC KEY BLOCK-----

This public key was then used to encrypt some message. I then received this sample non-encoded encrypted message in a (*.pgp) file that I need to decrypt using the private key generated.

WEÛπ*=‚d\Ì˝¯i⁄„˝∂FŒ™ç;ı\qä´©Õ·[. G»v‹4Ø˘∂0J˘ÏN8¡6ÓÿÖ÷Á{x_>À5ÉQug‘Ô}ôΩ\ò[@$¶rnò∂sƒ1E∂˛ 9M!üæd<˝GŸ^páwS”ö`Uó˙L"ª∑â˛T“û0EUΩÉ'£éZ¢Ïg∂fiH13èóƒíÁ⁄!∞èñ4ù(ÂC2ábñ§¥ªµìÀ(õ(Ô1'ü¥ªçh4
îD¬r?7œƒ?+†#ßGµ?±î<›+ä’ºÖ

My question is what is the simplest way to decrypt this encrypted message within the .pgp file?

I tried the following online tool: https://www.igolder.com/pgp/decryption/

but keep getting a unknown object in stream 22 error

  • To clarify: you control the public and private key used in these examples? – Royce Williams Oct 26 '17 at 0:26
3

That tool requires you to use ASCII armored encrypted files. Your example has issues as the encoding on a binary file as displayed in a text-editor is not unique (and the web application doesn't know how to interpret it properly).

The easiest way is to just use the command line with gpg (gpg and PGP are generally compatible when they follow the OpenPGP standard except in a few rare cases). For a complete example, you create a trusted key pair (again for this demo I chose no passphrase on the key) with:

$ gpg --gen-key
gpg (GnuPG) 1.4.20; Copyright (C) 2015 Free Software Foundation, Inc.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Please select what kind of key you want:
   (1) RSA and RSA (default)
[...]
Your selection? 1
[...]
Key expires at Thu 26 Oct 2017 01:58:43 PM EDT
Is this correct? (y/N) y

[...]
You selected this USER-ID:
    "john doe (don't use) <j@j.com>"
[...]    
gpg: key DA65E019 marked as ultimately trusted
public and secret key created and signed.

which in my case created a new trusted keypair called DA65E019.

Then I can encrypt a file without ASCII armoring it (basically encrypting in base64 with linebreaks):

$ gpg --encrypt --recipient DA65E019 test.txt

that creates a file called test.txt.gpg or with ASCII armoring it:

$ gpg --encrypt --armor --recipient DA65E019 test.txt

which creates an ASCII armored file called test.txt.asc.

-----BEGIN PGP MESSAGE-----
Version: GnuPG v1

hIwDLaGCjcd4AvcBA/wLm/sLb5yha7dPIz4288dtgR0a4zdynB+MZ1ikH8aVWi8x
w6aR3DoA5IyOQkg7whC2vWlWHaJLkrSOWYwnvHVSNm/bXVtXkLq9ZLWnvLVjux+E
+GVQDr8nCSdGR04ZfQ741LjDWubUzlZFacIlMuSmvMrfepIcl5i1ydr4UNA9OtJR
Ac0pgzY3odsl8nmcO+v9XmRpekDm8O3TTHAHN5ci1+iqxI6W/VOEHeuan8HW00Hh
E10+X0Sb5cNCNJBtrIE4G06F2JMKt53o4kTULiSPjT8A
=WEJE
-----END PGP MESSAGE-----

I can use your tool to decrypt this message with your online tool, by exporting my secret key:

$ gpg --armor --export-secret-key DA65E019
-----BEGIN PGP PRIVATE KEY BLOCK-----
Version: GnuPG v1

lQHYBFnw0OUBBADpSAnz6pdZYIyeRHJDi4AuTyEAmZTzFNbbS5Ble0wRnydzkl0o
/1pF0FpnkpFcutN2U1fQA/wVi2mYnUT5m3dY9kQVM9qaOShELg21wuqbvEjE+Y1f
+8+aTNY8f1eeLO6sDPZcpaGhiPxWfpb+uM5dke6DQ1wO+wZM/zXlRNjVAwARAQAB
AAP/W6pK/uV3g09E8gvDOndebtP5C9tNhBb0NkeC/d1tDp+TSP6CTNHKDxTH8VrO
c7mVzjEBmGN4cp7NZ4Kkz9AfHL3N9J2Y0VwoxtwkVgCFktvYFZZRBGI8tw5utxt1
T0dhPkBMDsPqoLushbooymPKbl9vGTZGMmPD1PWCRBc/yUECAO7qowO1J7PAoR0+
p3Z1mWfUXqD1eRuT5WL/MpP8+aUf5LxjeFqBweC3IWRSO6F6G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RXJdJ2G/0J3ZwQ83YqiFFIc9B1cC5b1Ji5u/prjPVeWVBHA1+gTptWiYgZi
PAugw5HilG4ec9egBJdVGGPPCQ+jNoilBBgBAgAPBQJZ8NDlAhsMBQkAAVGAAAoJ
EBD5wEzaZeAZHoMD/j92pvKe1mr8usWzYFecmZx8uyb1WouxqP+UeEQtry0+IfNJ
Qmlo5UbxYvn5KPg1WIcMOAXlDpm0neBuG/FCIhuUbXq4JVxV5tKJYw2I+Px6jiCD
HivTQ+/NgZdVMcB8k9PqyA96yVyct18KrDAAQ6l8xqzzxXefJRbUaqj8usG7
=yKJT
-----END PGP PRIVATE KEY BLOCK-----

or directly decrypt the binary file test.txt.gpg with gpg in the commandline:

$ gpg --decrypt test.txt.gpg
gpg: encrypted with 1024-bit RSA key, ID C77802F7, created 2017-10-25
      "john doe (don't use) <j@j.com>"
this is a file

In your example, you'll have to import the private key:

$ gpg --allow-secret-key-import --import secret_key.gpg.asc 

and then should be have the private key and can use it for decryption.

  • Thanks for the reply! Is there a way to use an existing public / private key with gpg cli? – AnchovyLegend Oct 25 '17 at 18:21
  • Followed the examples you mentioned, with creating a new key and getting the following error when trying to decrypt: unknown object in stream SecretSubkey – AnchovyLegend Oct 25 '17 at 18:34
  • Note, Version: GnuPG v1 isn't included in my encrypted message. – AnchovyLegend Oct 25 '17 at 18:43
0

The key is in this line:

 Version: BCPG C# v1.6.1.0

A quick search online says it was encrypted using the Bouncy Castle PGP library, so that's probably the best library to use to decrypt it. This link http://rafayal.blogspot.com/2009/06/pgp-decryption-with-c.html includes an example C# program using Bouncy Castle to decrypt a PGP encrypted message.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.