Store Files Securely in Oracle Storage Cloud Service

SCS supports encryption. With this mechanism you can store your files in SCS with an encryption key that you provide.

Here you are a java example:

package es.jmu.testscsencrypt;
import java.util.UUID;
public class TestEncrypt {
public static void main(String[] args) {
try {
Long t0 = System.currentTimeMillis();
CloudStorageConfig myConfig = new CloudStorageConfig();
// I’m creating a new keypair for each execution for simplification
// keypair should be retrieved from a keystore where it was stored previously, obvoiously!
KeyPairGenerator keyGen = KeyPairGenerator.getInstance(“RSA”);
SecureRandom random = SecureRandom.getInstance(“SHA1PRNG”, “SUN”);
keyGen.initialize(2048, random);
KeyPair kp = keyGen.generateKeyPair();
EncryptedCloudStorage es = CloudStorageFactory.getEncryptedStorage(myConfig);
//open the file
File f = new File(args[0]);
Long mbs = f.length()/1024/1024;
System.out.println(“Subiendo fichero ” + args[0] + ” de tamaño ” + mbs + ” Mbytes”);
FileInputStream fis = new FileInputStream(f);
//store file up there
es.storeObject(“testencrypt”, UUID.randomUUID().toString(), “text/plain”, fis);
Long durasegs = (System.currentTimeMillis() – t0)/1000;
System.out.println(“Ratio transferencia: ” + mbs/durasegs + ” MB/seg”);

// at this point you can take a look to the file stored and you’ll see it is encrypted

//see figure I

// now let’s get the bytes downloaded

StorageInputStream sis = es.retrieveObject(“testencrypt”, f.getName());
byte [] churro = new byte[102400];
int l = 0;
while(l >= 0){
l =;
if( l > 0 )System.out.println(new String(churro));

// as you can see the file is cleartext, see figure II
} catch (Exception e) {

Figure I


Figure II


Enjoy it 😉

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.