All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.bouncycastle.crypto.params.KeyParameter Maven / Gradle / Ivy

Go to download

The Bouncy Castle Crypto package is a Java implementation of cryptographic algorithms. This jar contains JCE provider and lightweight API for the Bouncy Castle Cryptography APIs for JDK 1.4.

There is a newer version: 1.79
Show newest version
package org.bouncycastle.crypto.params;

import org.bouncycastle.crypto.CipherParameters;
import org.bouncycastle.util.Arrays;

public class KeyParameter
    implements CipherParameters
{
    private byte[]  key;

    public KeyParameter(
        byte[]  key)
    {
        this(key, 0, key.length);
    }

    public KeyParameter(
        byte[]  key,
        int     keyOff,
        int     keyLen)
    {
        this(keyLen);

        System.arraycopy(key, keyOff, this.key, 0, keyLen);
    }

    private KeyParameter(int length)
    {
        this.key = new byte[length];
    }

    public void copyTo(byte[] buf, int off, int len)
    {
        if (key.length != len)
            throw new IllegalArgumentException("len");

        System.arraycopy(key, 0, buf, off, len);
    }

    public byte[] getKey()
    {
        return key;
    }

    public int getKeyLength()
    {
        return key.length;
    }

    public KeyParameter reverse()
    {
        KeyParameter reversed = new KeyParameter(key.length);
        Arrays.reverse(this.key, reversed.key);
        return reversed;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy