com.nimbusds.jose.crypto
Class MACSigner

java.lang.Object
  extended by com.nimbusds.jose.crypto.MACSigner
All Implemented Interfaces:
JWSAlgorithmProvider, JWSSigner

@ThreadSafe
public class MACSigner
extends Object
implements JWSSigner

Message Authentication Code (MAC) signer of JWS objects. This class is thread-safe.

Supports the following JSON Web Algorithms (JWAs):

Version:
$version$ (2013-05-16)
Author:
Vladimir Dzhuvinov

Constructor Summary
MACSigner(byte[] sharedSecret)
          Creates a new Message Authentication (MAC) signer.
MACSigner(String sharedSecretString)
          Creates a new Message Authentication (MAC) signer.
 
Method Summary
protected static String getJCAAlgorithmName(JWSAlgorithm alg)
          Gets the matching Java Cryptography Architecture (JCA) algorithm name for the specified HMAC-based JSON Web Algorithm (JWA).
 byte[] getSharedSecret()
          Gets the shared secret.
 String getSharedSecretString()
          Gets the shared secret as a UTF-8 encoded string.
 Base64URL sign(ReadOnlyJWSHeader header, byte[] signingInput)
          Signs the specified input of a JWS object.
 Set<JWSAlgorithm> supportedAlgorithms()
          Returns the names of the supported JWS algorithms.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.nimbusds.jose.JWSAlgorithmProvider
supportedAlgorithms
 

Constructor Detail

MACSigner

public MACSigner(byte[] sharedSecret)
Creates a new Message Authentication (MAC) signer.

Parameters:
sharedSecret - The shared secret. Must not be null.

MACSigner

public MACSigner(String sharedSecretString)
Creates a new Message Authentication (MAC) signer.

Parameters:
sharedSecretString - The shared secret as a UTF-8 encoded string. Must not be null.
Method Detail

sign

public Base64URL sign(ReadOnlyJWSHeader header,
                      byte[] signingInput)
               throws JOSEException
Description copied from interface: JWSSigner
Signs the specified input of a JWS object.

Specified by:
sign in interface JWSSigner
Parameters:
header - The JSON Web Signature (JWS) header. Must specify a supported JWS algorithm and must not be null.
signingInput - The input to sign. Must not be null.
Returns:
The resulting signature part (third part) of the JWS object.
Throws:
JOSEException - If the JWS algorithm is not supported or if signing failed for some other reason.

getJCAAlgorithmName

protected static String getJCAAlgorithmName(JWSAlgorithm alg)
                                     throws JOSEException
Gets the matching Java Cryptography Architecture (JCA) algorithm name for the specified HMAC-based JSON Web Algorithm (JWA).

Parameters:
alg - The JSON Web Algorithm (JWA). Must be supported and not null.
Returns:
The matching JCA algorithm name.
Throws:
JOSEException - If the algorithm is not supported.

getSharedSecret

public byte[] getSharedSecret()
Gets the shared secret.

Returns:
The shared secret.

getSharedSecretString

public String getSharedSecretString()
Gets the shared secret as a UTF-8 encoded string.

Returns:
The shared secret as a UTF-8 encoded string.

supportedAlgorithms

public Set<JWSAlgorithm> supportedAlgorithms()
Description copied from interface: JWSAlgorithmProvider
Returns the names of the supported JWS algorithms. These correspond to the alg JWS header parameter.

Specified by:
supportedAlgorithms in interface JWSAlgorithmProvider
Returns:
The supported JWS algorithms, empty set if none.


Copyright © 2013 NimbusDS. All Rights Reserved.