Search in sources :

Example 1 with SessionLevelConfig

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();
    }
}
Also used : NAEParameterSpec(com.ingrian.security.nae.NAEParameterSpec) NAEKey(com.ingrian.security.nae.NAEKey) NAESecretKey(com.ingrian.security.nae.NAESecretKey) SessionLevelConfig(com.ingrian.security.nae.SessionLevelConfig) NAESession(com.ingrian.security.nae.NAESession) IllegalBlockSizeException(javax.crypto.IllegalBlockSizeException) InvalidAlgorithmParameterException(java.security.InvalidAlgorithmParameterException) BadPaddingException(javax.crypto.BadPaddingException) NoSuchPaddingException(javax.crypto.NoSuchPaddingException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) InvalidKeyException(java.security.InvalidKeyException) NoSuchProviderException(java.security.NoSuchProviderException)

Aggregations

NAEKey (com.ingrian.security.nae.NAEKey)1 NAEParameterSpec (com.ingrian.security.nae.NAEParameterSpec)1 NAESecretKey (com.ingrian.security.nae.NAESecretKey)1 NAESession (com.ingrian.security.nae.NAESession)1 SessionLevelConfig (com.ingrian.security.nae.SessionLevelConfig)1 InvalidAlgorithmParameterException (java.security.InvalidAlgorithmParameterException)1 InvalidKeyException (java.security.InvalidKeyException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 NoSuchProviderException (java.security.NoSuchProviderException)1 BadPaddingException (javax.crypto.BadPaddingException)1 IllegalBlockSizeException (javax.crypto.IllegalBlockSizeException)1 NoSuchPaddingException (javax.crypto.NoSuchPaddingException)1