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 oracle.cloud.storage.*;
import java.io.*;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.SecureRandom;
import java.util.UUID;
public class TestEncrypt {
public static void main(String[] args) {
try {
Long t0 = System.currentTimeMillis();
CloudStorageConfig myConfig = new CloudStorageConfig();
myConfig.setServiceName(“Storage-0123456789”)
.setUsername(“sateloc”)
.setPassword(“obob”.toCharArray())
.setServiceUrl(“https://us2.storage.oraclecloud.com”);
// 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();
myConfig.setKeyPair(kp);
EncryptedCloudStorage es = CloudStorageFactory.getEncryptedStorage(myConfig);
System.out.println(“\nConnected!!\n”);
//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);
fis.close();
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 = sis.read(churro);
if( l > 0 )System.out.println(new String(churro));
}

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

Figure I

scsencryptI.png

Figure II

scsencryptII

Enjoy it 😉

IT

javier mugueta View All →

Me and my circumstance

Leave a Reply

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

WordPress.com Logo

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

Google photo

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

Twitter picture

You are commenting using your Twitter 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.

%d bloggers like this: