use of com.ingrian.security.nae.SessionLevelConfig in project CipherTrust_Application_Protection by thalescpl-io.
the class MultiplePropertyFileSample method main.
public static void main(String[] args) {
if (args.length != 6) {
System.err.println("Usage: java MultiplePropertyFileSample local_config_user local_config_password " + "local_propertyfile_path global_config_user global_config_password keyname");
System.exit(-1);
}
NAESession localsession = null;
NAESession globalsession = null;
NAESecretKey localsessionKey = null;
NAEKey globalsessionKey = null;
String data = "Test Data";
try {
localsession = NAESession.getSession(args[0], args[1].toCharArray(), new SessionLevelConfig(args[2]));
globalsession = NAESession.getSession(args[3], args[4].toCharArray());
NAEParameterSpec spec = new NAEParameterSpec(args[5], true, true, false, 192, null, localsession);
localsessionKey = generateKey(spec);
boolean isExported = exportKeyToGlobalSession(globalsession, localsessionKey);
if (isExported) {
byte[] encrytedText = encryptWithLocalConfig(data, localsessionKey);
globalsessionKey = NAEKey.getSecretKey(localsessionKey.getName(), globalsession);
byte[] decryptText = decryptWithGLobalConfig(encrytedText, globalsessionKey);
if (data.equals(new String(decryptText))) {
System.out.println("Key is exported successfully to global Key Manager.");
} else {
System.out.println("Key is not exported successfully to global Key Manager.");
}
} else {
System.out.println("Key is not exported successfully to global Key Manager.");
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if (localsessionKey != null)
localsessionKey.delete();
if (globalsessionKey != null)
globalsessionKey.delete();
}
}
Aggregations