Difference between revisions of "Common-utils-encryption"

From Gcube Wiki
Jump to: navigation, search
(Created page with '=== Scope === This library offers an easy way to encrypt and decrypt XML documents and String objects. It is based on a symmetric key based on the AES standard for cryptography. …')
 
Line 8: Line 8:
 
==== Encryption ====
 
==== Encryption ====
  
<src lang="java">
+
<source lang="java">
  
 
import org.gcube.common.utils.encryption.StringEncrypter;
 
import org.gcube.common.utils.encryption.StringEncrypter;
Line 15: Line 15:
 
resource.setAccessData(new StringEncrypter("my sensible data").encrypt());
 
resource.setAccessData(new StringEncrypter("my sensible data").encrypt());
  
</src>
+
</source>
  
 
After serialization, the resource will appears as follows:
 
After serialization, the resource will appears as follows:
<src lang="xml">
+
<source lang="xml">
 
<?xml version='1.0' encoding='UTF-8' standalone='yes' ?>
 
<?xml version='1.0' encoding='UTF-8' standalone='yes' ?>
 
<Resource version="0.4.x">
 
<Resource version="0.4.x">
Line 45: Line 45:
 
</Profile>
 
</Profile>
 
</Resource>
 
</Resource>
</src>
+
</source>
  
=== Decryption ===
+
==== Decryption ====
  
  
<src lang="java">
+
<source lang="java">
  
 
import org.gcube.common.utils.encryption.StringEncrypter;
 
import org.gcube.common.utils.encryption.StringEncrypter;
Line 59: Line 59:
 
System.out.println("Access data's content: " + ap.getAccessData());
 
System.out.println("Access data's content: " + ap.getAccessData());
  
</src>
+
</source>
  
 
This will print the following line:
 
This will print the following line:
<src lang="text">
+
<source lang="text">
 
Access data's content: my sensible data
 
Access data's content: my sensible data
</src>
+
</source>

Revision as of 22:54, 25 January 2012

Scope

This library offers an easy way to encrypt and decrypt XML documents and String objects. It is based on a symmetric key based on the AES standard for cryptography.

Sample Usage

These samples are taken from the exploitation the resource library does of the encryption library for protecting the AccessData content of the RuntimeResource class.

Encryption

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

After serialization, the resource will appears as follows:

<?xml version='1.0' encoding='UTF-8' standalone='yes' ?>
<Resource version="0.4.x">
	<ID>ac41d0d0-4791-11e1-b442-a3a8a4cd06fd</ID>
	<Type>RuntimeResource</Type>
	<Profile>
		<Category>test category</Category>
		<Name>resource name</Name>
		<Description>a description</Description>
		<Platform>
			<Name>Test platform</Name>
			<Version>1</Version>
			<MinorVersion>1</MinorVersion>
		</Platform>
		<RunTime>
			<HostedOn>macos-manuele</HostedOn>
			<GHN UniqueID="123456789"/>
			<Status>READY</Status>
		</RunTime>
		<AccessPoint>
			<Interface>
				<Endpoint EntryName="ap">http://myaccesspoint.eu</Endpoint>
			</Interface>
			<AccessData>dtvKM4JImPLQvboHwBvKEur1tbvdnKXYB82AICLq5/c=</AccessData>
		</AccessPoint>
	</Profile>
</Resource>

Decryption

import org.gcube.common.utils.encryption.StringEncrypter;
 
//...
AccessPoint ap = new AccessPoint();
ap.setAccessData(new StringEncrypter(this.load("AccessData")).decrypt());
System.out.println("Access data's content: " + ap.getAccessData());

This will print the following line:

Access data's content: my sensible data