This content originally appeared on DEV Community and was authored by wennan xu
Document
https://pgpainless.readthedocs.io/en/latest/quickstart.html
Setup
// If you use Gradle
...
dependencies {
...
implementation "org.pgpainless:pgpainless-core:1.7.2"
...
}
// If you use Maven
...
<dependencies>
...
<dependency>
<groupId>org.pgpainless</groupId>
<artifactId>pgpainless-core</artifactId>
<version>1.7.2</version>
</dependency>
...
</dependencies>
What's ASCII Armor
ASCII armor is a layer of radix64 encoding that can be used to wrap binary OpenPGP data in order to make it save to transport via text-based channels (e.g. email bodies).
The way in which ASCII armor can be applied depends on the type of data that you want to protect. The easies way to ASCII armor an OpenPGP key or certificate is by using PGPainless’ asciiArmor() method:
PGPPublicKey certificate = ...;
String asciiArmored = PGPainless.asciiArmor(certificate);
How to Encrypt message or file
- Suppose you have a
FileInputStream
orByteArrayInputStream
. Then also you need to have aOutputStream
, like
OutputStream outputStream =
Files.newOutputStream(outputFileLocation, StandardOpenOption.CREATE_NEW);
- Before you call the
Painless.encryptAndOrSign()
, you need to build up theProducerOptions
. It will be likeProducerOptions options = ProducerOptions.signAndEncrypt(signingOptions, encryptionOptions);
This content originally appeared on DEV Community and was authored by wennan xu

wennan xu | Sciencx (2025-03-09T00:02:38+00:00) How to use pgpainless-core. Retrieved from https://www.scien.cx/2025/03/09/how-to-use-pgpainless-core/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.