net.adamcin.httpsig.hmac
Class HmacKey

java.lang.Object
  extended by net.adamcin.httpsig.hmac.HmacKey
All Implemented Interfaces:
Key

public class HmacKey
extends Object
implements Key


Constructor Summary
HmacKey(String keyId, String secret)
          Instantiates a new HMAC key with an identifier and a secret used to sign
 
Method Summary
 boolean canSign()
          HMAC Keys can always be used to sign
 boolean canVerify()
          HMAC Keys can always be used to verify
 Set<Algorithm> getAlgorithms()
           
 String getId()
           
 byte[] sign(Algorithm algorithm, byte[] contentBytes)
          Signs the challengeHash using the specified signature Algorithm
 boolean verify(Algorithm algorithm, byte[] contentBytes, byte[] signatureBytes)
          Verifies the signatureBytes against the challengeHash using an underlying public key
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HmacKey

public HmacKey(String keyId,
               String secret)
Instantiates a new HMAC key with an identifier and a secret used to sign

Parameters:
keyId - The keys identifier
secret - The secret used to sign
Method Detail

getId

public String getId()
Specified by:
getId in interface Key
Returns:
the Key's self-identification. This may end up not being unique within a keychain.

getAlgorithms

public Set<Algorithm> getAlgorithms()
Specified by:
getAlgorithms in interface Key
Returns:
the Set of Signature Algorithms supported by this key.

canVerify

public boolean canVerify()
HMAC Keys can always be used to verify

Specified by:
canVerify in interface Key
Returns:
always true

verify

public boolean verify(Algorithm algorithm,
                      byte[] contentBytes,
                      byte[] signatureBytes)
Verifies the signatureBytes against the challengeHash using an underlying public key

Specified by:
verify in interface Key
Parameters:
algorithm - the selected Signature Algorithm
contentBytes - the result of RequestContent.getContent(java.util.List, java.nio.charset.Charset)
signatureBytes - the result of Authorization.getSignatureBytes()
Returns:
true if signature is valid

canSign

public boolean canSign()
HMAC Keys can always be used to sign

Specified by:
canSign in interface Key
Returns:
always true

sign

public byte[] sign(Algorithm algorithm,
                   byte[] contentBytes)
Signs the challengeHash using the specified signature Algorithm

Specified by:
sign in interface Key
Parameters:
algorithm - the selected Signature Algorithm
contentBytes - the result of RequestContent.getContent(java.util.List, java.nio.charset.Charset)
Returns:
byte array containing the challengeHash signature or null if a signature could not be generated.


Copyright © 2014. All Rights Reserved.