Last active
March 1, 2019 10:58
-
-
Save alximw/8a00c031919ea28ec242be52a3be6e98 to your computer and use it in GitHub Desktop.
Decryption routines from the Tosiok samples
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
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