Search in sources :

Example 6 with NAECipher

use of com.ingrian.security.nae.NAECipher 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

NAECipher (com.ingrian.security.nae.NAECipher)6 NAEKey (com.ingrian.security.nae.NAEKey)5 GCMParameterSpec (com.ingrian.security.nae.GCMParameterSpec)3 IngrianProvider (com.ingrian.security.nae.IngrianProvider)3 NAEAESGCMCipher (com.ingrian.security.nae.NAEAESGCMCipher)3 NAESession (com.ingrian.security.nae.NAESession)3 NAEException (com.ingrian.security.nae.NAEException)2 InvalidAlgorithmParameterException (java.security.InvalidAlgorithmParameterException)2 InvalidKeyException (java.security.InvalidKeyException)2 Key (java.security.Key)2 PrivateKey (java.security.PrivateKey)2 PublicKey (java.security.PublicKey)2 Scanner (java.util.Scanner)2 SecretKey (javax.crypto.SecretKey)2 NAEARIACipher (com.ingrian.security.nae.NAEARIACipher)1 NAESEEDCipher (com.ingrian.security.nae.NAESEEDCipher)1 SecureRandom (java.security.SecureRandom)1 IvParameterSpec (javax.crypto.spec.IvParameterSpec)1