Search in sources :

Example 1 with NAEARIACipher

use of com.ingrian.security.nae.NAEARIACipher in project CipherTrust_Application_Protection by thalescpl-io.

the class FileEncryptionSampleUsingARIA method main.

public static void main(String[] args) {
    if (args.length != 8) {
        System.err.println("Usage: java FileEncryptionSampleUsingARIA user password keyname fileToEncrypt " + "encryptedFile decryptedFile iv blockSize");
        System.exit(-1);
    }
    String username = args[0];
    String password = args[1];
    String keyName = args[2];
    String srcName = args[3];
    String dstName = args[4];
    String decrName = args[5];
    String iv = args[6];
    int blockSize = Integer.parseInt(args[7]);
    byte[] ivBytes = iv.getBytes();
    System.out.println("iv: " + IngrianProvider.byteArray2Hex(ivBytes));
    String Algo = "ARIA/CBC/PKCS5Padding";
    Security.addProvider(new IngrianProvider());
    NAESession session = null;
    try {
        session = NAESession.getSession(username, password.toCharArray());
        NAEKey key = NAEKey.getSecretKey(keyName, session);
        // IvParameterSpec ivSpec = new
        // IvParameterSpec(IngrianProvider.hex2ByteArray(iv));
        NAECipher cipher = NAECipher.getNAECipherInstance(Algo, "IngrianProvider");
        cipher.init(Cipher.ENCRYPT_MODE, key);
        NAEARIACipher aria = cipher.get_aria();
        aria.update(srcName, dstName, blockSize, cipher);
        cipher.init(Cipher.DECRYPT_MODE, key);
        aria = cipher.get_aria();
        aria.update(dstName, decrName, blockSize, cipher);
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        if (session != null) {
            session.closeSession();
        }
    }
}
Also used : NAEKey(com.ingrian.security.nae.NAEKey) NAECipher(com.ingrian.security.nae.NAECipher) NAESession(com.ingrian.security.nae.NAESession) NAEARIACipher(com.ingrian.security.nae.NAEARIACipher) IngrianProvider(com.ingrian.security.nae.IngrianProvider)

Aggregations

IngrianProvider (com.ingrian.security.nae.IngrianProvider)1 NAEARIACipher (com.ingrian.security.nae.NAEARIACipher)1 NAECipher (com.ingrian.security.nae.NAECipher)1 NAEKey (com.ingrian.security.nae.NAEKey)1 NAESession (com.ingrian.security.nae.NAESession)1