Search in sources :

Example 1 with CryptoDataUtility

use of com.gemalto.ps.keysecure.crypto.CryptoDataUtility in project CipherTrust_Application_Protection by thalescpl-io.

the class CryptoDataUtilitySample method main.

public static void main(String[] args) throws Exception {
    if (args.length != 5) {
        System.out.println("Usage: java CryptoDataUtilitySample <username>" + " <password>" + " <keyname>" + "<transformation>" + "<text>");
        System.exit(-1);
    }
    String userName = args[0];
    String password = args[1];
    String keyName = args[2];
    String transformation = args[3];
    String text = args[4];
    byte[] plaintext = text.getBytes("UTF-8");
    // change as needed
    NAESession session = NAESession.getSession(userName, password.toCharArray());
    // this constructor defaults to using SecureRandom for IV generation which is slow but more secure
    CryptoDataUtility utility = new CryptoDataUtility(session);
    // method will generate a random IV for you
    byte[] ciphertext = utility.encrypt(plaintext, keyName, transformation);
    System.out.println("Encrypted: " + new String(ciphertext, "UTF-8"));
    byte[] decrypted = utility.decrypt(ciphertext);
    System.out.println("Decrypted: " + new String(decrypted, "UTF-8"));
}
Also used : CryptoDataUtility(com.gemalto.ps.keysecure.crypto.CryptoDataUtility) NAESession(com.ingrian.security.nae.NAESession)

Aggregations

CryptoDataUtility (com.gemalto.ps.keysecure.crypto.CryptoDataUtility)1 NAESession (com.ingrian.security.nae.NAESession)1