Created
July 22, 2012 16:03
-
-
Save d6y/3160130 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Apache 2 license | |
| public static void main(final String... args) throws GeneralSecurityException, IOException | |
| { | |
| if (args.length != 4 && args.length != 2) | |
| { | |
| System.err.println("Usage: Decrypt [-alg algorithm] KEY FILE"); | |
| System.exit(1); | |
| } | |
| final String alg; | |
| final String key; | |
| final File encryptedFile; | |
| if (args.length == 4) | |
| { | |
| alg = args[1]; | |
| key = args[2]; | |
| encryptedFile = new File(args[3]); | |
| } | |
| else // use defaults for algorithm: | |
| { | |
| alg = "PBEWithMD5AndDES"; | |
| key = args[0]; | |
| encryptedFile = new File(args[1]); | |
| } | |
| final EncryptionUtil eu = new EncryptionUtil(key, alg, EncryptionUtil.DEFAULT_VERSION); | |
| CipherInputStream decrypt=null; | |
| BufferedOutputStream outStream=null; | |
| try | |
| { | |
| decrypt = eu.decrypt(new FileInputStream(encryptedFile)); | |
| IOUtils.copy(decrypt, System.out); | |
| } | |
| finally | |
| { | |
| IOUtils.closeQuietly(decrypt); | |
| IOUtils.closeQuietly(System.out); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment