/** * Gets a cipher for algorithm/mode/padding in config value * commons.crypto.cipher.transformation * * @param transformation the name of the transformation, e.g., * <i>AES/CBC/PKCS5Padding</i>. * See the Java Cryptography Architecture Standard Algorithm Name Documentation * for information about standard transformation names. * @return CryptoCipher the cipher object (defaults to OpenSslCipher if available, else JceCipher) * @throws GeneralSecurityException if JCE cipher initialize failed */ public static CryptoCipher getCryptoCipher(String transformation) throws GeneralSecurityException { return getCryptoCipher(transformation, new Properties()); }
Properties props) throws GeneralSecurityException { final List<String> names = Utils.splitClassNames(getCipherClassString(props), ","); if (names.size() == 0) { throw new IllegalArgumentException("No classname(s) provided");
/** * Helper method to create a CryptoCipher instance and throws only * IOException. * * @param props The <code>Properties</code> class represents a set of * properties. * @param transformation the name of the transformation, e.g., * <i>AES/CBC/PKCS5Padding</i>. * See the Java Cryptography Architecture Standard Algorithm Name Documentation * for information about standard transformation names. * @return the CryptoCipher instance. * @throws IOException if an I/O error occurs. */ public static CryptoCipher getCipherInstance( String transformation, Properties props) throws IOException { try { return CryptoCipherFactory.getCryptoCipher(transformation, props); } catch (GeneralSecurityException e) { throw new IOException(e); } }
private void initializeForAuth(String cipher, byte[] nonce, SecretKeySpec key) throws GeneralSecurityException { // commons-crypto currently only supports ciphers that require an initial vector; so // create a dummy vector so that we can initialize the ciphers. In the future, if // different ciphers are supported, this will have to be configurable somehow. byte[] iv = new byte[conf.ivLength()]; System.arraycopy(nonce, 0, iv, 0, Math.min(nonce.length, iv.length)); encryptor = CryptoCipherFactory.getCryptoCipher(cipher, cryptoConf); encryptor.init(Cipher.ENCRYPT_MODE, key, new IvParameterSpec(iv)); decryptor = CryptoCipherFactory.getCryptoCipher(cipher, cryptoConf); decryptor.init(Cipher.DECRYPT_MODE, key, new IvParameterSpec(iv)); }
private void initializeForAuth(String cipher, byte[] nonce, SecretKeySpec key) throws GeneralSecurityException { // commons-crypto currently only supports ciphers that require an initial vector; so // create a dummy vector so that we can initialize the ciphers. In the future, if // different ciphers are supported, this will have to be configurable somehow. byte[] iv = new byte[conf.ivLength()]; System.arraycopy(nonce, 0, iv, 0, Math.min(nonce.length, iv.length)); encryptor = CryptoCipherFactory.getCryptoCipher(cipher, cryptoConf); encryptor.init(Cipher.ENCRYPT_MODE, key, new IvParameterSpec(iv)); decryptor = CryptoCipherFactory.getCryptoCipher(cipher, cryptoConf); decryptor.init(Cipher.DECRYPT_MODE, key, new IvParameterSpec(iv)); }
private void initializeForAuth(String cipher, byte[] nonce, SecretKeySpec key) throws GeneralSecurityException { // commons-crypto currently only supports ciphers that require an initial vector; so // create a dummy vector so that we can initialize the ciphers. In the future, if // different ciphers are supported, this will have to be configurable somehow. byte[] iv = new byte[conf.ivLength()]; System.arraycopy(nonce, 0, iv, 0, Math.min(nonce.length, iv.length)); encryptor = CryptoCipherFactory.getCryptoCipher(cipher, cryptoConf); encryptor.init(Cipher.ENCRYPT_MODE, key, new IvParameterSpec(iv)); decryptor = CryptoCipherFactory.getCryptoCipher(cipher, cryptoConf); decryptor.init(Cipher.DECRYPT_MODE, key, new IvParameterSpec(iv)); }
/** * Gets CryptoCipher from pool. * * @return the CipherState instance. * @throws IOException if an I/O error occurs. */ private CipherState getCipherState() throws IOException { CipherState state = cipherPool.poll(); if (state == null) { CryptoCipher cryptoCipher; try { cryptoCipher = CryptoCipherFactory.getCryptoCipher("AES/CTR/NoPadding", props); } catch (GeneralSecurityException e) { throw new IOException(e); } state = new CipherState(cryptoCipher); } return state; }
CryptoCipherFactory.getCryptoCipher("AES/CTR/NoPadding", props); System.out.println("Cipher instance created OK");