Package iu.crypt

Class Jws

java.lang.Object
iu.crypt.Jws
All Implemented Interfaces:
WebSignature

public class Jws extends Object implements WebSignature
JSON implementation of WebSignature.
  • Constructor Details

    • Jws

      Jws(JsonObject protectedHeader, Jose header, byte[] signature)
      Creates a new signed message;
      Parameters:
      protectedHeader - JWS protected header
      header - JWS unprotected header
      signature - signature
  • Method Details

    • getHeader

      public WebCryptoHeader getHeader()
      Description copied from interface: WebSignature
      Gets the signature header.
      Specified by:
      getHeader in interface WebSignature
      Returns:
      WebCryptoHeader
    • getSignature

      public byte[] getSignature()
      Description copied from interface: WebSignature
      Gets the signature data.
      Specified by:
      getSignature in interface WebSignature
      Returns:
      signature data
    • verify

      public void verify(byte[] payload, WebKey key)
      Description copied from interface: WebSignature
      Verifies the signature as valid.
      Specified by:
      verify in interface WebSignature
      Parameters:
      payload - payload to verify the signature against
      key - (public or shared) key to use for verifying the signature
    • componentLength

      static int componentLength(WebKey.Type type)
      Gets the expected signature component length by key type.
      Parameters:
      type - key type
      Returns:
      expected signature component length
    • toJce

      static byte[] toJce(WebKey.Type type, WebKey.Algorithm algorithm, byte[] jwaSignature)
      Converts a signature from JWA format to JCE
      Parameters:
      type - key type
      algorithm - algorithm
      jwaSignature - JWA formatted signature
      Returns:
      JCE formatted signature
    • fromJce

      static byte[] fromJce(WebKey.Type type, WebKey.Algorithm algorithm, byte[] jceSignature)
      Converts a signature from JCE format to JWA
      Parameters:
      type - key type
      algorithm - algorithm
      jceSignature - JCE calculated signature
      Returns:
      JWA formatted signature
    • parse

      static Jws parse(JsonValue jwsSignature)
      Parses per-signature JWS parameters from raw JSON.
      Parameters:
      jwsSignature - JSON
      Returns:
      parsed JWS parameters
    • serializeTo

      void serializeTo(JsonObjectBuilder json)
      Adds JWS per-signature parameters to a JsonObjectBuilder.
      Parameters:
      json - JsonObjectBuilder
    • getSignatureInput

      String getSignatureInput(byte[] payload)
      Gets the signature input.
      Parameters:
      payload - payload
      Returns:
      signature input