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

org.spongycastle.tls.crypto.impl.jcajce.JceTlsMAC Maven / Gradle / Ivy

Go to download

Spongy Castle is a package-rename (org.bouncycastle.* to org.spongycastle.*) of Bouncy Castle intended for the Android platform. Android unfortunately ships with a stripped-down version of Bouncy Castle, which prevents easy upgrades - Spongy Castle overcomes this and provides a full, up-to-date version of the Bouncy Castle cryptographic libs.

There is a newer version: 1.58.0.0
Show newest version
package org.spongycastle.tls.crypto.impl.jcajce;

import java.security.InvalidKeyException;

import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;

import org.spongycastle.tls.crypto.TlsMAC;

/**
 * A basic wrapper for a JCE Mac class to provide the needed functionality for TLS.
 */
public class JceTlsMAC
    implements TlsMAC
{
    private final String algorithm;

    private Mac mac;

    public JceTlsMAC(Mac mac, String algorithm)
    {
        this.mac = mac;
        this.algorithm = algorithm;
    }

    public void setKey(byte[] key)
    {
        try
        {
            mac.init(new SecretKeySpec(key, algorithm));
        }
        catch (InvalidKeyException e)
        {
            e.printStackTrace();
        }
    }

    public void update(byte[] input, int inOff, int length)
    {
        mac.update(input, inOff, length);
    }

    public byte[] calculateMAC()
    {
        return mac.doFinal();
    }

    public int getMacLength()
    {
        return mac.getMacLength();
    }

    public void reset()
    {
        mac.reset();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy