java.lang.Object
io.inverno.mod.security.jose.internal.JOSEUtils

public class JOSEUtils extends Object

JOSE utilities class.

Since:
1.5
Author:
Jeremy Kuhn
  • Field Details

    • DEFAULT_SECURE_RANDOM

      public static final SecureRandom DEFAULT_SECURE_RANDOM
      Default secure random.
    • BASE64_NOPAD_URL_ENCODER

      public static final Base64.Encoder BASE64_NOPAD_URL_ENCODER
      Base64URL encoder without padding.
  • Constructor Details

    • JOSEUtils

      public JOSEUtils()
  • Method Details

    • toPaddedUnsignedBytes

      public static byte[] toPaddedUnsignedBytes(BigInteger value, int length) throws JWKProcessingException

      Returns the integer value as an unsigned byte array of the specified length padded with leading zeros.

      In RFC7518 Section 6.2 it is not clearly specify that x, y and d must be converted to unsigned byte arrays however it is specified that their size must be that of a coordinate for the specified curve as a result we must get rid of the sign bit. Note that elliptic curve coordinates are always positive integers.

      Parameters:
      value - an integer
      length - the length
      Returns:
      a byte array
      Throws:
      JWKProcessingException
    • toUnsignedBytes

      public static byte[] toUnsignedBytes(BigInteger value)

      Converts the specified integer value to unsigned byte array.

      Parameters:
      value - the integer to convert
      Returns:
      the integer as unsigned byte array
    • toUnsignedBytes

      public static byte[] toUnsignedBytes(int value)

      Converts the specified integer value to unsigned byte array.

      Parameters:
      value - the integer to convert
      Returns:
      the integer as unsigned byte array
    • generateInitializationVector

      public static byte[] generateInitializationVector(SecureRandom secureRandom, int length)

      Generates an initialization vector of the specified length using the specified secure random.

      Parameters:
      secureRandom - a secure random
      length - the initialization vector length
      Returns:
      an initialization vector
    • generateSalt

      public static byte[] generateSalt(SecureRandom secureRandom, int length)

      Generates a salt of the specified length using the specified secure random.

      Parameters:
      secureRandom - a secure random
      length - the initialization vector length
      Returns:
      a salt
    • toX509CertificateSha1Thumbprint

      public static String toX509CertificateSha1Thumbprint(X509Certificate certificate) throws JWKProcessingException

      Returns the X.509 SHA1 thumbprint of the specified certificate.

      Parameters:
      certificate - an X.509 certificate
      Returns:
      an X.509 SHA1 thumbprint
      Throws:
      JWKProcessingException - if there was an error generating the thumbprint
    • toX509CertificateSha256Thumbprint

      public static String toX509CertificateSha256Thumbprint(X509Certificate certificate) throws JWKProcessingException

      Returns the X.509 SHA256 thumbprint of the specified certificate.

      Parameters:
      certificate - an X.509 certificate
      Returns:
      an X.509 SHA1 thumbprint
      Throws:
      JWKProcessingException - if there was an error generating the thumbprint