Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PGPException : checksum mismatch at 0 of 20 #3

Open
ramjia2z opened this issue Aug 9, 2021 · 2 comments
Open

PGPException : checksum mismatch at 0 of 20 #3

ramjia2z opened this issue Aug 9, 2021 · 2 comments

Comments

@ramjia2z
Copy link

ramjia2z commented Aug 9, 2021

Decryption flow is throwing exception at this point [no changes made]

return pgpSecKey.extractPrivateKey(pass, "BC");

@bbbgit
Copy link

bbbgit commented Aug 11, 2022

Had the same issue. Apparently the keys/passphrase are invalid, I have generated new keys and now it works.

@damienlancry
Copy link

Having the same issue.
@bbbgit Could you please elaborate on how you generated your keys and exported them to file?
In particular what algorithm did you use to generate the keys? Is it one of the following?

   (1) RSA and RSA
   (2) DSA and Elgamal
   (3) DSA (sign only)
   (4) RSA (sign only)
   (9) ECC (sign and encrypt) *default*
  (10) ECC (sign only)

I tried to generate my own keys but I am having a new error:

java.io.IOException: unknown PGP public key algorithm encountered

The full log is this:

>>> mvn exec:java -Dexec.mainClass=com.test.pgp.bc.BCPGPTest
[INFO] Scanning for projects...
[INFO]
[INFO] --------------------< com.test.pgp.bc:BCPGPExample >--------------------
[INFO] Building Bouncy Castle OpenPGP encryption and decryption example 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- exec-maven-plugin:3.1.0:java (default-cli) @ BCPGPExample ---
[WARNING]
java.io.IOException: unknown PGP public key algorithm encountered
    at org.bouncycastle.bcpg.PublicKeyPacket.<init> (Unknown Source)
    at org.bouncycastle.bcpg.BCPGInputStream.readPacket (Unknown Source)
    at org.bouncycastle.openpgp.PGPPublicKeyRing.<init> (Unknown Source)
    at org.bouncycastle.openpgp.PGPObjectFactory.nextObject (Unknown Source)
    at org.bouncycastle.openpgp.PGPPublicKeyRingCollection.<init> (Unknown Source)
    at com.test.pgp.bc.BCPGPUtils.readPublicKey (BCPGPUtils.java:27)
    at com.test.pgp.bc.BCPGPEncryptor.setPublicKeyFilePath (BCPGPEncryptor.java:88)
    at com.test.pgp.bc.BCPGPTest.encryptFile (BCPGPTest.java:26)
    at com.test.pgp.bc.BCPGPTest.main (BCPGPTest.java:12)
    at org.codehaus.mojo.exec.ExecJavaMojo$1.run (ExecJavaMojo.java:279)
    at java.lang.Thread.run (Thread.java:748)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  0.673 s
[INFO] Finished at: 2022-10-13T13:41:31+08:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:3.1.0:java (default-cli) on project BCPGPExample: An exception occurred while executing the Java class. unknown PGP public key algorithm encountered -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

I generated my keys like this (using all the default arguments and "passphrase" as passphrase):

>>> gpg --full-generate-key
gpg (GnuPG) 2.3.7; Copyright (C) 2021 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
   (2) DSA and Elgamal
   (3) DSA (sign only)
   (4) RSA (sign only)
   (9) ECC (sign and encrypt) *default*
  (10) ECC (sign only)
  (14) Existing key from card
Your selection?
Please select which elliptic curve you want:
   (1) Curve 25519 *default*
   (4) NIST P-384
   (6) Brainpool P-256
Your selection?
Please specify how long the key should be valid.
         0 = key does not expire
      <n>  = key expires in n days
      <n>w = key expires in n weeks
      <n>m = key expires in n months
      <n>y = key expires in n years
Key is valid for? (0)
Key does not expire at all
Is this correct? (y/N) y

GnuPG needs to construct a user ID to identify your key.

Real name: dl
Email address:
Comment:
You selected this USER-ID:
    "dl"

Change (N)ame, (C)omment, (E)mail or (O)kay/(Q)uit? o
We need to generate a lot of random bytes. It is a good idea to perform
some other action (type on the keyboard, move the mouse, utilize the
disks) during the prime generation; this gives the random number
generator a better chance to gain enough entropy.
We need to generate a lot of random bytes. It is a good idea to perform
some other action (type on the keyboard, move the mouse, utilize the
disks) during the prime generation; this gives the random number
generator a better chance to gain enough entropy.
gpg: revocation certificate stored as '/Users/dlancry/.gnupg/openpgp-revocs.d/7A122D352C277C719BAA93D9C96852CB921655D2.rev'
public and secret key created and signed.

pub   ed25519 2022-10-13 [SC]
      7A122D352C277C719BAA93D9C96852CB921655D2
uid                      dl
sub   cv25519 2022-10-13 [E]

then exported the keys to file like that:

gpg --output test.gpg.pub --export dl; gpg --output test.gpg.prv --export-secret-key dl

I am using this version of gpg: (installed with brew)

>>> gpg --version
gpg (GnuPG) 2.3.7
libgcrypt 1.10.1
Copyright (C) 2021 Free Software Foundation, Inc.
License GNU GPL-3.0-or-later <https://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Home: /Users/dlancry/.gnupg
Supported algorithms:
Pubkey: RSA, ELG, DSA, ECDH, ECDSA, EDDSA
Cipher: IDEA, 3DES, CAST5, BLOWFISH, AES, AES192, AES256, TWOFISH,
        CAMELLIA128, CAMELLIA192, CAMELLIA256
AEAD: EAX, OCB
Hash: SHA1, RIPEMD160, SHA256, SHA384, SHA512, SHA224
Compression: Uncompressed, ZIP, ZLIB, BZIP2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants