-
-
Save skydogch/338bc54de7709db32e4b to your computer and use it in GitHub Desktop.
This file contains 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 byte[] decrypt(byte[] data, byte[] key) | |
{ | |
// 16 bytes is the IV size for AES256 | |
try | |
{ | |
PaddedBufferedBlockCipher cipher = new PaddedBufferedBlockCipher(new CBCBlockCipher(new AESFastEngine())); | |
byte[] ivBytes = new byte[16]; | |
System.arraycopy(data, 0, ivBytes, 0, ivBytes.length); // Get iv from data | |
byte[] dataonly = new byte[data.length - ivBytes.length]; | |
System.arraycopy(data, ivBytes.length, dataonly, 0, data.length - ivBytes.length); | |
cipher.init(false, new ParametersWithIV(new KeyParameter(key), ivBytes)); | |
byte[] decrypted = new byte[cipher.getOutputSize(dataonly.length)]; | |
int len = cipher.processBytes(dataonly, 0, dataonly.length, decrypted,0); | |
len += cipher.doFinal(decrypted, len); | |
return decrypted; | |
} | |
catch(Exception e) | |
{ | |
e.printStackTrace(); | |
} | |
return null; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment