Java ByteBuffer Size decryptData(final ByteBuffer buffer, final int size, final int key)

Here you can find the source of decryptData(final ByteBuffer buffer, final int size, final int key)

Description

Decrypts the given encrypted data with the specified key.

License

Apache License

Parameter

Parameter Description
buffer a buffer wrapping the encrypted data to be decrypted
size size of the buffer in bytes
key the decryption key

Return

the byte buffer wrapping the decrypted data

Declaration

public static ByteBuffer decryptData(final ByteBuffer buffer, final int size, final int key) 

Method Source Code

//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;
    }
}

Related

  1. convolve(final BufferedImage image, float[] elements, int theWidth, int theHeight)
  2. cover(BufferedImage source, File to, Image cover, int width, int height, int sourceTop, int sourceLeft, int sourceWidth, int sourceHeight)
  3. cutAndScaleToRoundSquare(BufferedImage src, int size, int radius)
  4. cutAndScaleToSquare(BufferedImage src, int size)
  5. decreaseBufferCapatity(final ByteBuffer byteBuffer, final int size, final int minSize)
  6. depthToGrayBufferedImage(int[] depth, int width, int height)
  7. doThumb(BufferedImage from, int width, int height)
  8. enhance(int size, ByteBuffer bbuf)
  9. ensureBufferCapacity(final int width, final int height, BufferedImage img)