Here you can find the source of decryptData(final ByteBuffer buffer, final int size, final int key)
Parameter | Description |
---|---|
buffer | a buffer wrapping the encrypted data to be decrypted |
size | size of the buffer in bytes |
key | the decryption key |
public static ByteBuffer decryptData(final ByteBuffer buffer, final int size, final int key)
//package com.java2s; //License from project: Apache License import java.nio.ByteBuffer; public class Main { /** A number table used by the decryption and hashing algorithms. */ private static final long[] CRYPT_TABLE = new long[0x500]; /**/*from w w w . ja v a2s .c om*/ * Decrypts the given encrypted data with the specified key. * * <p> * The decryption will wrap the data with a byte buffer, and decrypt inside that (it shares the original byte buffer). * * @param buffer a buffer wrapping the encrypted data to be decrypted * @param size size of the buffer in bytes * @param key the decryption key * @return the byte buffer wrapping the decrypted data */ public static ByteBuffer decryptData(final ByteBuffer buffer, final int size, final int key) { long seed1 = key & 0xFFFF_FFFFL; long seed2 = 0xEEEE_EEEEL; int ch; for (int i = 0; i < size; i += 4) { seed2 = (seed2 + CRYPT_TABLE[0x400 + (int) (seed1 & 0xFF)]) & 0xFFFF_FFFFL; ch = buffer.getInt(i) ^ (int) (seed1 + seed2); seed1 = ((((~seed1 & 0xFFFF_FFFFL) << 0x15) + 0x1111_1111L) & 0xFFFF_FFFFL) | (seed1 >> 0x0B); seed2 = ((ch & 0xFFFF_FFFFL) + seed2 + (seed2 << 5) + 3) & 0xFFFF_FFFFL; buffer.putInt(i, ch); } buffer.position(0); return buffer; } }