From Gcube Wiki
Jump to: navigation, search


This library offers an easy way to encrypt and decrypt string objects.

Design and implementation notes

The "common-encryption" library is a refactoring of the old library named: "common-utils-encryption" but the focus of new library is only the string object. The library uses a symmetric key based on the AES standard algorithm for cryptography. It does expect that such a key is available on the local classpath. Optionally, the key can be programmatically passed to the methods exposed by the Encrypters.

If the key is not programmatically passed, the library load a different simmetric key according to the VO scope:


for scope "/gcube/devsec" load file: "devsec.gcubekey";

for scope "/gcube" load file: "gcube.gcubekey";

for scope "/gcube/devsec/devVRE" load file: "devsec.gcubekey" (the VO ).

In addition, the resulting encrypted data are encoded in the BASE 64 schema in order to represent them in the ASCII string format.

The library uses only java standard libraries.

It exposes a main class:

  • StringEncrypter for encrypting/decrypting String objects


Maven coordinates

The maven artifact coordinates are:


Check on Nexus for the latest version.

String Encryption

This and the following sample are taken from the exploitation the resource library does of the encryption library for protecting the AccessData content of the RuntimeResource class.

The following snippet shows how to encrypt a string:

import org.gcube.common.encryption.StringEncrypter;
resource.setAccessData(StringEncrypter.getEncrypter().encrypt("my sensible data"));

After its serialization, the resource appears as follows:

<?xml version='1.0' encoding='UTF-8' standalone='yes' ?>
<Resource version="0.4.x">
		<Category>test category</Category>
		<Name>resource name</Name>
		<Description>a description</Description>
			<Name>Test platform</Name>
			<GHN UniqueID="123456789"/>
				<Endpoint EntryName="ap"></Endpoint>
			<AccessData>dtvKM4JImPLQvboHwBvKEur1tbvdnKXYB82AICLq5/c=</AccessData> <!-- here's the encrypted data -->

String Decryption

The following snippet shows how to decrypt a string:

import org.gcube.common.encryption.StringEncrypter;
AccessPoint ap = new AccessPoint();
System.out.println("Access data's content: " + ap.getAccessData());

This will print the following line:

Access data's content: my sensible data