Skip to content

Instantly share code, notes, and snippets.

@alximw
Last active March 1, 2019 10:58
Show Gist options
  • Save alximw/8a00c031919ea28ec242be52a3be6e98 to your computer and use it in GitHub Desktop.
Save alximw/8a00c031919ea28ec242be52a3be6e98 to your computer and use it in GitHub Desktop.
Decryption routines from the Tosiok samples
private static void decryptFile(InputStream in, String destFilePath) throws Exception {
File destFile = new File(destFilePath);
if (in != null) {
if (!destFile.getParentFile().exists()) {
destFile.getParentFile().mkdirs();
}
destFile.createNewFile();
FileOutputStream out = new FileOutputStream(destFile);
SecretKeySpec secretKeySpec = new SecretKeySpec(new SecretKeySpec(Base64.decode("GiEhjghmZIO7RTWyycQ9PQ=="), "AES").getEncoded(), "AES");
Cipher cipher = Cipher.getInstance("AES");
cipher.init(2, secretKeySpec);
CipherOutputStream cout = new CipherOutputStream(out, cipher);
byte[] cache = new byte[1024];
int index = 0;
while (true) {
int nRead = in.read(cache);
if (nRead == -1) {
cout.close();
out.close();
in.close();
return;
}
cout.write(cache, 0, nRead);
cout.flush();
index++;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment