/** * Convenience method without key length parameter. See {@link OpenSSLPKCS5CipherProvider#getCipher(EncryptionMethod, String, int, boolean)} * * @param encryptionMethod the {@link EncryptionMethod} * @param password the secret input * @param encryptMode true for encrypt, false for decrypt * @return the initialized cipher * @throws Exception if there is a problem initializing the cipher */ public Cipher getCipher(EncryptionMethod encryptionMethod, String password, boolean encryptMode) throws Exception { return getCipher(encryptionMethod, password, new byte[0], -1, encryptMode); }
/** * Returns the hex-encoded hash of the specified value. The default charset ({@code StandardCharsets.UTF_8}) is used. * * @param algorithm the hash algorithm to use * @param value the value to hash (cannot be {@code null} but can be an empty String) * @return the hash value in hex */ public static String hashValue(HashAlgorithm algorithm, String value) { return hashValue(algorithm, value, StandardCharsets.UTF_8); }
/** * Returns the raw {@code byte[]} hash of the specified value. The default charset ({@code StandardCharsets.UTF_8}) is used. * * @param algorithm the hash algorithm to use * @param value the value to hash (cannot be {@code null} but can be an empty String) * @return the hash value in bytes */ public static byte[] hashValueRaw(HashAlgorithm algorithm, String value) { return hashValueRaw(algorithm, value, StandardCharsets.UTF_8); }
@Override public void process(final InputStream in, final OutputStream out) throws IOException { // Initialize cipher provider KeyedCipherProvider cipherProvider = (KeyedCipherProvider) CipherProviderFactory.getCipherProvider(KeyDerivationFunction.NONE); // Generate cipher try { Cipher cipher = cipherProvider.getCipher(encryptionMethod, key, iv, true); cipherProvider.writeIV(cipher.getIV(), out); CipherUtility.processStreams(cipher, in, out); } catch (Exception e) { throw new ProcessException(e); } } }
/** * Returns an initialized cipher for the specified algorithm. The IV will be generated internally (for encryption). If decryption is requested, it will throw an exception. * * @param encryptionMethod the {@link EncryptionMethod} * @param key the key * @param encryptMode true for encrypt, false for decrypt * @return the initialized cipher * @throws Exception if there is a problem initializing the cipher or if decryption is requested */ @Override public Cipher getCipher(EncryptionMethod encryptionMethod, SecretKey key, boolean encryptMode) throws Exception { return getCipher(encryptionMethod, key, new byte[0], encryptMode); }
@Override public byte[] readSalt(InputStream in) throws IOException, ProcessException { return readSalt(EncryptionMethod.AES_CBC, in); }
public void writeIV(byte[] iv, OutputStream out) throws IOException { CipherUtility.writeBytesToOutputStream(out, iv, "IV", IV_DELIMITER); } }
@Override public byte[] readSalt(InputStream in) throws IOException, ProcessException { return CipherUtility.readBytesFromInputStream(in, "salt", MAX_SALT_LIMIT, SALT_DELIMITER); }
@Override public StreamCallback getEncryptionCallback() throws ProcessException { return new EncryptCallback(); }
@Override public StreamCallback getEncryptionCallback() throws Exception { return new OpenPGPEncryptCallback(algorithm, provider, password, filename); }
@Override public StreamCallback getDecryptionCallback() throws Exception { return new OpenPGPDecryptCallback(provider, password); }
@Override public StreamCallback getDecryptionCallback() throws Exception { return new OpenPGPDecryptCallback(provider, keyring, passphrase); }
@Override public StreamCallback getDecryptionCallback() throws ProcessException { return new DecryptCallback(); }
@Override public StreamCallback getEncryptionCallback() throws Exception { return new OpenPGPEncryptCallback(algorithm, provider, keyring, userId, filename); }
@Override public StreamCallback getDecryptionCallback() throws ProcessException { return new DecryptCallback(); }
@Override public StreamCallback getEncryptionCallback() throws ProcessException { return new EncryptCallback(); }
@Override public void writeSalt(byte[] salt, OutputStream out) throws IOException { CipherUtility.writeBytesToOutputStream(out, salt, "salt", SALT_DELIMITER); }
/** * Convenience method without key length parameter. See {@link OpenSSLPKCS5CipherProvider#getCipher(EncryptionMethod, String, byte[], int, boolean)} * * @param encryptionMethod the {@link EncryptionMethod} * @param password the secret input * @param salt the salt * @param encryptMode true for encrypt, false for decrypt * @return the initialized cipher * @throws Exception if there is a problem initializing the cipher */ public Cipher getCipher(EncryptionMethod encryptionMethod, String password, byte[] salt, boolean encryptMode) throws Exception { return getCipher(encryptionMethod, password, salt, -1, encryptMode); }
public byte[] readIV(InputStream in) throws IOException, ProcessException { return CipherUtility.readBytesFromInputStream(in, "IV", MAX_IV_LIMIT, IV_DELIMITER); }
public void writeIV(byte[] iv, OutputStream out) throws IOException { CipherUtility.writeBytesToOutputStream(out, iv, "IV", IV_DELIMITER); } }