OpenPGP Library for Java News

Articles related to DidiSoft OpenPGP Library for Java

OpenPGP Library for Java v3.1.3.6 with a critical bugfix

Today has been released version of DidiSoft OpenPGP Library for Java which provides a critical bug fix.

The bug prevents decrypting .pgp data that was encrypted and compressed with the BZip-2 algorithm. The error message thrown in such cases is:

com.didisoft.pgp.PGPException: I/O problem with stream: Not a BZIP2 marked stream : Not a BZIP2 marked stream : Not a BZIP2 marked stream

Versions affected: all 3.0.x and 3.1.x versions.

Other recent updates

Release date: 08 October 2018
KeyStore class – fixed bug in importing keys with only a comment header line

Release date: 25 September 2018
PGPLib class – default preferred symmetric key cipher is now AES-256, with backward compatibility with keys made prior year 2002 using CAST5
As usual the latest version should be fully backward compatible and the upgrade shall be nothing more than replacing your existing JAR files with those from the latest release.

Shall you have any questions or concerns, please do not hesitate to drop us a line.


GnuPG 2.2.8 compatibility with Java

Recent changes in GnuPG version 2.2.8 in response to the EFAIL attack reject all encrypted data that don’t have Modification Detection Code (MDC) packet.

In order to address this as of version DidiSoft OpenPGP Library for Java exposes a new property in the PGPLib class:


Example usage:

PGPLib pgp = new PGPLib();

Setting this property will have affect on all subsequent encryption or one pass signing and encryption calls that don’t have the integrity check parameter. When the above property is set to true, integrity protection (Modification Detection Code) packet will be added to the encrypted data in the .pgp message to be compatible with GnuPG 2.2.8 and all new upcoming versions.

This change is especially for all methods that produce String output, because in those methods the integrity protection was missing up till now.


Brainpool ECC curves support for Java

As of version of DidiSoft OpenPGP Library for Java Elliptic Curve (ECC) OpenPGP keys can be created over the field of Brainpool curves.

Usage of keys based on the Brainpool curves was possible by older versions of the library, but it couldn’t create keys based on them.

These Elliptic Curves are not yet a part of the ECC OpenPGP standard, but were adopted by GnuPG/gpg, so we had to catch up in order to be able to provide functionality for creating OpenPGP based on them. The curves are available as enumeration members in the EcCurve.Enum type:


and as String values:


and can be used with the new method KeyStore.generateEccKeyPair that accepts EcCurve.Enum parameters, or the overloaded versions that accept the ECC curve by name.

Below is an example code that demonstrates this new functionality:

import com.didisoft.pgp.*;
public class GenerateKeyPairECC {
	public static void main(String[] args) throws Exception {
		// initialize the KeyStore where the key will be generated
		KeyStore ks = new KeyStore("examples/DataFiles/pgp.keystore", "changeit");
		// key primary user Id
		String userId = "<>";
		// preferred hashing algorithms
		HashAlgorithm.Enum[] hashingAlgorithms = new HashAlgorithm.Enum[]
		// preferred compression algorithms
		CompressionAlgorithm.Enum[] compressions = new CompressionAlgorithm.Enum[] 
		// preferred symmetric key algorithms
		CypherAlgorithm.Enum[] cyphers = new CypherAlgorithm.Enum[] 
		String privateKeyPassword = "changeit";
		EcCurve.Enum masterEcCurve = EcCurve.Enum.Brainpool512;
		EcCurve.Enum encryptionEcCurve = EcCurve.Enum.Brainpool512;
		int expiresAfterDays = 0; // never expires
		KeyPairInformation key = ks.generateEccKeyPair(masterEcCurve,
		System.out.println("Generated a " + masterEcCurve.toString() + "/" + encryptionEcCurve.toString() + " ECC OpenPGP key");


What’s Next?

In the upcoming months we are going to provide support for Curve25519 which is one of the fastest ECC curves and is not known to be part of any patent yet.


Heap Inspection fix in OpenPGP Library for Java

A memory dump of the Java Virtual Machine can reveal passwords stored in class members in clear text (String variables, char arrays, etc.) and until recently DidiSoft OpenPGP Library for Java was impacted by this security threat. Thanks to a hint from an Intel team we have made steps in order to fix those issues. The two classes that were affected were com.didisoft.pgp.KeyStore and

As of version 3.1.3 of the library all passwords available as class member variables are stored in javax.crypto.SealedObject. The class constructors you are already familiar with, still have a minimal security concern that the encryption key is a class member, although being a secure random value randomized at each instantiation.

Version 3.1.3 introduces constructors with on demand password encryption key

The new thing in version 3.1.3 are the additional class constructors that provide a thorough security measure in keeping the SealedObject encryption key in a Listener interface implementation, provided as parameter. The interface has only one simple method that must provide the encryption key (AES) :

public interface ICustomKeyListener {
	 * Returns the bytes of the encryption key used for securing a {@link SealedObject} 
	 * @param sender class instance invoking this method
	 * @return encryption key used for securing a {@link SealedObject}
	public byte[] getKey(Object sender);

The returned key doesn’t have to align with any of the supported AES key sizes (128, 192, 256 bits), because it will be hashed and padded internally. You can provide even shorter keys (although not recommended) like : new byte[] { 1, 2, 3, }

Here is a simple implementation demonstrated with the additional KeyStore class constructor:

KeyStore ks = new KeyStore("my.keystore", "password", new ICustomKeyListener() {			
	public byte[] getKey(Object sender) {
		return new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14. 15, 16 };

Note: Of course in a real world scenario probably the method will return a configuration value from a settings property file.

The same usage scenario applied to the LDAPClient class.


Maven repository

After years finally we’ve made the step to offer a private Maven repository for DidiSoft OpenPGP Library for Java.

The traditional way of downloading new versions from our customers’ section will remain as well but for development teams that rely on Maven as build tool, switching to a newer version of the library will be just changing the version number in their pom.xml

That’s why we’ve released version which is just mavenized If you wish to swith to the Maven integration described below you have to start from the new version

Maven Integration how-to

In your ~/.m2/settings.xml you have to specify your login credentials (the same email used for accessing our customers’ section)

<settings xmlns=""
            <username>email address for accessing DidiSoft Customers section</username>
            <password>email address for accessing DidiSoft Customers section</password>

And in your project pom.xml you have to define the URL of our repository:

<project xmlns="" xmlns:xsi=""

The final step is to actually define the pgplib JAR file as dependency in your project pom.xml:


Specifying only the version of the pgplib JAR is enough, the dependent versions of our shaded BouncyCastle version will be downloaded.

Shaded BouncyCastle

The BouncyCastle JAR files that we use are a shaded version of the original BouncyCastle jars but with the org.bouncycastle package naming changed to lw.bouncycastle (this is in order to avoid class loading collisions).


A great part of this effort was made with the help of Mykel Alvis from Cotivity.


Long Hex Key ID’s in OpenPGP Library for Java

In relation to the recent threats related to faking Linus Torvalds’ public key by providing a key with the same lower 4 bytes of the Key ID (the same short hexadecimal key ID) we have updated DidiSoft OpenPGP Library for Java to provide full support to long key ID’s.

What is a short Key ID

A short Key ID consists of a the low 4 bytes of the real Key ID which is of type java.lang.Long and is 8 bytes long. So the threat was someone to try to generates multiple keys until there is a key with the same lower 4 bytes as your key. Command line PGP and GnuPG tools are usually used by specifying the short Key ID like:

gpg --encrypt --recipient A3B26901

With our library you can specify a key with the hexadecimal key ID everywhere where a KeyStore and User ID parameters are expected. For example:

PGPLib pgp = new PGPLib();
KeyStore ks = new KeyStore("my.keystore", "keystore pass");
boolean asciiArmor = true;
String shortKeyID = "A3B26901";pgp.encryptFile("data.txt", ks, shortKeyID, "data.pgp", asciiArmor);

As of version we can use long key ID’s as well:

PGPLib pgp = new PGPLib();
KeyStore ks = new KeyStore("my.keystore", "keystore pass");
boolean asciiArmor = true;
String longKeyID = "B21345CA3B26901";pgp.encryptFile("data.txt", ks, longKeyID, "data.pgp", asciiArmor);



OpenPGP Library for Java 3.1.1 has been released

DidiSoft OpenPGP Library for Java version 3.1.1 has been released.

This version brings improved speed for generating Diffie-Hellman (DH/DSS) keys, ability to add and remove sub keys and a new KeyStore.importKey method.

Speed of DH/DSS key creation

Till now by default the time needed for generating an ElGamal  (Diffie-Hellman) based OpenPGP key with the library was impractically long and for keys with key sizes greater than 2048 bits was not suitable for a real world application.

As of version 3.1.1 by default the library uses the public values for the p and g components of the Diffie-Hellman key exchange algorithm defined in RFC 3526. If you still wish to obtain your own p and g for newly generated key, you can do so by switching off the usePrecomputedPrimes property of the KeyStore class:

KeyStore ks = new KeyStore();

Additional sub keys

This version also allows the creation of additional sub keys. Check the examples how to create and add a new sub key to an existing key pair and how to remove a sub key.

New importKey method

The existing methods for importing individual keys into a com.didisoft.pgp.KeyStore were cumbersome, because the result from the operation was an array of com.didisoft.pgp.KeyPairInformation objects, instead of a single object. Now you can use a new KeyStore.importKey method instead that works over private, public and combined keys.


OpenPGP for Java version 3.1 was released

DidiSoft OpenPGP Library for Java version 3.1 was released today.

New way to check digital signatures

The major change in this release is a new way to check the outcome of OpenPGP digital signatures verification and the introduction of a new enum com.didisoft.pgp.SignatureCheckResult

/** Represents the result of an OpenPGP signature check */
public enum SignatureCheckResult {
    /** Signature verified with the provided public key(s) */
    /** Signature broken or forged */
    /** The signature wasn't made with the provided public key */
    /** No signature was found in the input data */

Till now the outcome of checking signatures was a boolean result. When it was true it was clear that the signature is correct. The problem was when the result was false. In that case it was unclear was the signature tempered, or we have used a wrong public key to check it, or there was no signature in the .pgp message at all.

In order to solve this weakness a new set of methods was introduced:

PGPLib.verifyAndExtract verifies an OpenPGP signed or clear text signed message and extracts the data
PGPLib.verifyWithoutExtracting verifies an OpenPGP signed or clear text signed message without extracts the data
PGPLib.decryptAndVerify verifies an OpenPGP signed and encrypted message and extracts the data
PGPLib.detachedVerify verifies an OpenPGP detached signature

All of the above mentioned methods return com.didisoft.pgp.SignatureCheckResult which recognizes four cases : the signature is OK, the signature is tempered, we have tried to check with a wrong key / or in case when we use a KeyStore there is no matching key and finally the specified .pgp message has no digital signature at all.

Te benefit of this new API is that the outcome is more accurate and there is no need of additional checks with PGPInspectLib in order to investigate the fault cases.

Backward compatibility

Upgrading is safe and will not harm your application. All the existing methods will stay although marked as obsolete. The reason for marking them obsolete is to encourage new application development to use the more accurate new set of methods.


Announcing OpenPGP Library for Java 3.0.0

Today has been released version 3.0.0 of DidiSoft OpenPGP Library for Java.

Why version 3.0?

The major version number change is made due to two main things:

1) The library no longer needs the Unlimited JCE (Java Cryptography Extensions) policy files. This means that from now on the library can be used in any application without modification in the host machine Java VM installation. The main benefit from this change is for mass market applications especially for B2C applications that have to be installed with minimal interventions on the client computer.

2) The library now can run side by side with any other version of the BouncyCastle library. You just have to use the library JAR files (located in the \Library folder of the distribution ZIP file) in your application classpath, no matter if there are any other versions of the BouncyCastle library.

Upgrade instructions

The upgrade consists of replacing the old JAR files with the new ones:

1) bcpg-jdk15on-15-lw.jar
2) bcprov-jdk15on-15-lw.jar
3) pgplib-3.0.0.jar

Java 1.4 dropped

The library no longer ships with JAR files built for Java 1.4. Please let us know if you still need that version, and we will include it for you!

The DidiSoft Team


Announcing OraPGP

OpenPGP for Oracle DB

Announcing DidiSoft OraPGP, a package of PL/SQL functions for the Oracle(c) Database platform version 11 and 12 offering OpenPGP cryptography functions.

The package conforms to the OpenPGP standard RFC 4880 and RFC 6637, with compatibility to the older standard RFC 1991.

The package is licensed per server and also an Enterprise wide license is available, which ships with an Enterprise License for DidiSoft OpenPGP Library for Java as an extra add-on.