Skip to content

Instantly share code, notes, and snippets.

@skydogch
Forked from romanman/gist:b1a379339afe49e5c65b
Last active October 17, 2015 21:10
Show Gist options
  • Save skydogch/338bc54de7709db32e4b to your computer and use it in GitHub Desktop.
Save skydogch/338bc54de7709db32e4b to your computer and use it in GitHub Desktop.
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