Bouncy Castle PGP Decryption Issue

后端 未结 2 2018
一整个雨季
一整个雨季 2021-02-18 21:37

I\'ve had a application using Bouncy Castle for PGP decryption which has run without any issues for the past 8 months or so, and the past 2 days all of a sudden an issue has com

相关标签:
2条回答
  • 2021-02-18 22:10

    This could be important (Source: http://www.opensourcejavaphp.net/csharp/itextsharp/PgpPublicKeyEncryptedData.cs.html) :

    It explains the value of your keyData.Algorithm being different, but the why I am still unsure of. It is most likely the input file that is the case. It could be different (client using a different key?)

    private static IBufferedCipher GetKeyCipher(
                PublicKeyAlgorithmTag algorithm)
            {
                try
                {
                    switch (algorithm)
                    {
                        case PublicKeyAlgorithmTag.RsaEncrypt:
                        case PublicKeyAlgorithmTag.RsaGeneral:
                            return CipherUtilities.GetCipher("RSA//PKCS1Padding");
                        case PublicKeyAlgorithmTag.ElGamalEncrypt:
                        case PublicKeyAlgorithmTag.ElGamalGeneral:
                            return CipherUtilities.GetCipher("ElGamal/ECB/PKCS1Padding");
                        default:
                            throw new PgpException("unknown asymmetric algorithm: " + algorithm);
                    }
                }
                catch (PgpException e)
                {
                    throw e;
                }
                catch (Exception e)
                {
                    throw new PgpException("Exception creating cipher", e);
                }
            }
    
    0 讨论(0)
  • 2021-02-18 22:18

    Looks like another party is encrypting to other/different keys. Probably your keyring contains RSA key as well, but BouncyCastle uses only the first (???). Using gpg, you can check the contents of your encrypted file by issuing gpg --list-packets YourEncryptedFile.pgp

    After that apply the same command to 'good' file, and to your keyrings, and compare key identifiers to which file is encrypted. Since you are using DSA keys, file should be encrypted to ElGamal subkey.

    0 讨论(0)
提交回复
热议问题