Click here to Skip to main content
15,938,218 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hi,
I am trying to encrypt a file using a public key (e.g. abc_public.asc) generated through PGPTool, which was shared with the client. The client shared a private key (xyz.asc) in return, in which the PGPTool shows as 'Public' (xyz.asc) and 'Key Pair' (abc_public.asc).

I am able to encrypt the file successfully, however when trying to decrypt it throws "Org.BouncyCastle.Bcpg.OpenPgp.PgpException: 'Org.BouncyCastle.Bcpg.OpenPgp.PgpPublicKeyRing found where PgpSecretKeyRing expected'"

The encrypted file when trying to decrypt with the PGPTool, it works but not through the code. Please help where am I going wrong.

What I have tried:

PGPEncryptDecrypt.EncryptFile(@"C:\test\test.txt", @"C:\test\test.txt.pgp",
         @"C:\test\abc_public.asc", false, true);


   PGPEncryptDecrypt.Decrypt(@"C:\test\test.txt.pgp", @"C:\test\xyz.asc", "hello@2022",
       @"C:\test\test_app.txt");
Posted
Updated 1-Nov-22 22:32pm
Comments
Member 15627495 2-Nov-22 3:22am    
the decrypt error tell you "wrong pgpsecretkeyring"
runtime_terror 2-Nov-22 7:32am    
Yes. What Am I supposed to do to overcome this error?

1 solution

Maybe you can find an example here: Search CodeProject PGP[^]

This might be the solution to your problem: PGP Decryption - Unnecessary exception stops execution · Issue #143 · bcgit/bc-csharp · GitHub[^]
 
Share this answer
 
v2
Comments
runtime_terror 2-Nov-22 7:31am    
Hi @RickZeeland, I have almost tried all the links and all of them throw the same error.
Am I doing something wrong with the keys or do I need to expect a secret key from the key I am using to decrypt? Am bit confused!!!
RickZeeland 2-Nov-22 7:34am    
It' confusing stuff and I'm not familiar with it either, maybe you can search further on GitHub for more information.
runtime_terror 3-Nov-22 5:36am    
It works with Didisoft, but not with BouncyCastle!!!
RickZeeland 3-Nov-22 5:57am    
Did you use the GitHub solution?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900