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

org.bouncycastle.jcajce.SecretKeyWithEncapsulation 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.5 to JDK 1.8.

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

import javax.crypto.SecretKey;

import org.bouncycastle.util.Arrays;

/**
 * Carrier class for a KEM/KTS secret key plus its encapsulation.
 */
public final class SecretKeyWithEncapsulation
    implements SecretKey
{
    private final SecretKey secretKey;
    private final byte[] encapsulation;

    /**
     * Basic constructor.
     *
     * @param secretKey the secret key that was arrived at.
     * @param encapsulation the encapsulation the key data was carried in.
     */
    public SecretKeyWithEncapsulation(SecretKey secretKey, byte[] encapsulation)
    {
        this.secretKey = secretKey;
        this.encapsulation = Arrays.clone(encapsulation);
    }

    /**
     * Return the algorithm for the agreed secret key.
     *
     * @return the secret key value.
     */
    public String getAlgorithm()
    {
        return secretKey.getAlgorithm();
    }

    /**
     * Return the format for the agreed secret key.
     *
     * @return the secret key format.
     */
    public String getFormat()
    {
        return secretKey.getFormat();
    }

    /**
     * Return the encoding of the agreed secret key.
     *
     * @return the secret key encoding.
     */
    public byte[] getEncoded()
    {
        return secretKey.getEncoded();
    }

    /**
     * Return the encapsulation that carried the key material used in creating the agreed secret key.
     *
     * @return the encrypted encapsulation of the agreed secret key.
     */
    public byte[] getEncapsulation()
    {
        return Arrays.clone(encapsulation);
    }

    public boolean equals(Object o)
    {
        return secretKey.equals(o);
    }

    public int hashCode()
    {
        return secretKey.hashCode();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy