pgpainless / pgpainless

Simple to use OpenPGP API based on Bouncy Castle
https://pgpainless.org
Apache License 2.0
153 stars 23 forks source link

How do you configure this to not use BouncyCastle? #441

Closed DarthHater closed 2 weeks ago

DarthHater commented 4 months ago

Describe the bug

This isn't really a bug, just a request for an example.

Expected behavior

I am interested in using this library in the absence of bouncy castle. The README states it can be configured to be used with JCE or BouncyCastle, but I can't seem to find any documentation on this, and perusing the source of both sop and core, bouncy castle seems to be pretty embedded.

Additional context

Thanks in advance!

vanitasvitae commented 4 months ago

Hey! Bouncycastles bcpg provides two different implementations of the OpenPGP protocol, one based on BCs lightweight crypto implementation and one relying on JCE instead.

Currently, BCs lightweight OpenPGP implementation is the default in PGPainless. However, you can at runtime swap the use of these classes out for their JCA/JCE counterparts by calling:

ImplementationFactory.setFactoryImplementation(new JceImplementationFactory());

This will result in JCE classes to be used instead. Note though, that this does not mean that you can use PGPainless without having Bouncycastle in your classpath, as BC is providing the classes which use JCE in the first place. PGPainless still depends on bcpg (BCs OpenPGP implementation).

It is also possible to replace BouncyCastleProvider (from bcprov) with a different SecurityProvider by calling

ProviderFactory.factory = new MySecurityProviderFactory(); // extends ProviderFactory

but I still haven't found a suitable alternative SecurityProvider that provides all the necessary algorithms and ciphers needed for OpenPGP.

Hope that helps you :)

DarthHater commented 4 months ago

Bouncy Castle seems to be the only game in town for PGP in Java, and while it's great it exists, it's just nice to know if alternatives exist, thank you for the thorough answer!