
com.nimbusds.jose.crypto.MACSigner Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of nimbus-jose-jwt Show documentation
Show all versions of nimbus-jose-jwt Show documentation
Java library for Javascript Object Signing and Encryption (JOSE) and
JSON Web Tokens (JWT)
package com.nimbusds.jose.crypto;
import net.jcip.annotations.ThreadSafe;
import com.nimbusds.jose.JOSEException;
import com.nimbusds.jose.JWSSigner;
import com.nimbusds.jose.JWSHeader;
import com.nimbusds.jose.util.Base64URL;
/**
* Message Authentication Code (MAC) signer of
* {@link com.nimbusds.jose.JWSObject JWS objects}. This class is thread-safe.
*
* Supports the following JSON Web Algorithms (JWAs):
*
*
* - {@link com.nimbusds.jose.JWSAlgorithm#HS256}
*
- {@link com.nimbusds.jose.JWSAlgorithm#HS384}
*
- {@link com.nimbusds.jose.JWSAlgorithm#HS512}
*
*
* @author Vladimir Dzhuvinov
* @version $version$ (2014-07-08)
*/
@ThreadSafe
public class MACSigner extends MACProvider implements JWSSigner {
/**
* Creates a new Message Authentication (MAC) signer.
*
* @param sharedSecret The shared secret. Must not be {@code null}.
*/
public MACSigner(final byte[] sharedSecret) {
super(sharedSecret);
}
/**
* Creates a new Message Authentication (MAC) signer.
*
* @param sharedSecretString The shared secret as a UTF-8 encoded
* string. Must not be {@code null}.
*/
public MACSigner(final String sharedSecretString) {
super(sharedSecretString);
}
@Override
public Base64URL sign(final JWSHeader header, final byte[] signingInput)
throws JOSEException {
String jcaAlg = getJCAAlgorithmName(header.getAlgorithm());
byte[] hmac = HMAC.compute(jcaAlg, getSharedSecret(), signingInput, provider);
return Base64URL.encode(hmac);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy