Skip to content

Instantly share code, notes, and snippets.

@d6y
Created July 22, 2012 16:03
Show Gist options
  • Select an option

  • Save d6y/3160130 to your computer and use it in GitHub Desktop.

Select an option

Save d6y/3160130 to your computer and use it in GitHub Desktop.
// 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