public byte[] decrypt(byte[] encryptedData, String password) { if (passwordEncoder.checkPassword(password)) { StandardPBEByteEncryptor cipher = new StandardPBEByteEncryptor(); cipher.setAlgorithm(algorithm); cipher.setPassword(password); return cipher.decrypt(encryptedData); } else { LOGGER.error("password not matched!!!"); throw new IllegalArgumentException("password not matched!!!"); } }
public void decrypt(File encryptedFile, String password, File trgtFile) throws FileNotFoundException, IOException { FileReader fr = null; FileOutputStream fos = null; BufferedReader br = null; BufferedOutputStream bos = null; if (passwordEncoder.checkPassword(password)) { StandardPBEByteEncryptor cipher = new StandardPBEByteEncryptor(); cipher.setAlgorithm(algorithm); cipher.setPassword(password); try { fr = new FileReader(encryptedFile); br = new BufferedReader(fr); fos = new FileOutputStream(trgtFile); bos = new BufferedOutputStream(fos); byte[] encrypted = null; byte[] decrypted = null; String line = null; while ((line = br.readLine()) != null) { try { encrypted = base64.decode(line.getBytes("US-ASCII")); } catch (Exception e) { throw new RuntimeException(e); } decrypted = cipher.decrypt(encrypted); bos.write(decrypted); } bos.flush(); } finally { EgovResourceReleaser.close(fos, bos, fr, br); } } else { LOGGER.error("password not matched!!!"); throw new IllegalArgumentException("password not matched!!!"); } }