Class CryptoHelper


  • class CryptoHelper
    extends java.lang.Object
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static byte JWT_PART_SEPARATOR  
    • Constructor Summary

      Constructors 
      Constructor Description
      CryptoHelper()  
    • Method Summary

      All Methods Instance Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      (package private) byte[] createSignatureFor​(java.lang.String algorithm, byte[] secretBytes, byte[] contentBytes)
      Deprecated.
      rather use corresponding method which takes header and payload as separate inputs
      (package private) byte[] createSignatureFor​(java.lang.String algorithm, byte[] secretBytes, byte[] headerBytes, byte[] payloadBytes)
      Create signature for JWT header and payload.
      (package private) byte[] createSignatureFor​(java.lang.String algorithm, java.security.PrivateKey privateKey, byte[] contentBytes)
      Deprecated.
      rather use corresponding method which takes header and payload as separate inputs
      (package private) byte[] createSignatureFor​(java.lang.String algorithm, java.security.PrivateKey privateKey, byte[] headerBytes, byte[] payloadBytes)
      Create signature for JWT header and payload using a private key.
      (package private) boolean verifySignatureFor​(java.lang.String algorithm, byte[] secretBytes, byte[] contentBytes, byte[] signatureBytes)
      Deprecated.
      rather use corresponding method which takes header and payload as separate inputs
      (package private) boolean verifySignatureFor​(java.lang.String algorithm, byte[] secretBytes, byte[] headerBytes, byte[] payloadBytes, byte[] signatureBytes)
      Verify signature for JWT header and payload.
      (package private) boolean verifySignatureFor​(java.lang.String algorithm, byte[] secretBytes, java.lang.String header, java.lang.String payload, byte[] signatureBytes)
      Verify signature for JWT header and payload.
      (package private) boolean verifySignatureFor​(java.lang.String algorithm, java.security.PublicKey publicKey, byte[] contentBytes, byte[] signatureBytes)
      Deprecated.
      rather use corresponding method which takes header and payload as separate inputs
      (package private) boolean verifySignatureFor​(java.lang.String algorithm, java.security.PublicKey publicKey, byte[] headerBytes, byte[] payloadBytes, byte[] signatureBytes)
      Verify signature for JWT header and payload using a public key.
      (package private) boolean verifySignatureFor​(java.lang.String algorithm, java.security.PublicKey publicKey, java.lang.String header, java.lang.String payload, byte[] signatureBytes)
      Verify signature for JWT header and payload.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • CryptoHelper

        CryptoHelper()
    • Method Detail

      • verifySignatureFor

        boolean verifySignatureFor​(java.lang.String algorithm,
                                   byte[] secretBytes,
                                   java.lang.String header,
                                   java.lang.String payload,
                                   byte[] signatureBytes)
                            throws java.security.NoSuchAlgorithmException,
                                   java.security.InvalidKeyException
        Verify signature for JWT header and payload.
        Parameters:
        algorithm - algorithm name.
        secretBytes - algorithm secret.
        header - JWT header.
        payload - JWT payload.
        signatureBytes - JWT signature.
        Returns:
        true if signature is valid.
        Throws:
        java.security.NoSuchAlgorithmException - if the algorithm is not supported.
        java.security.InvalidKeyException - if the given key is inappropriate for initializing the specified algorithm.
      • verifySignatureFor

        boolean verifySignatureFor​(java.lang.String algorithm,
                                   byte[] secretBytes,
                                   byte[] headerBytes,
                                   byte[] payloadBytes,
                                   byte[] signatureBytes)
                            throws java.security.NoSuchAlgorithmException,
                                   java.security.InvalidKeyException
        Verify signature for JWT header and payload.
        Parameters:
        algorithm - algorithm name.
        secretBytes - algorithm secret.
        headerBytes - JWT header.
        payloadBytes - JWT payload.
        signatureBytes - JWT signature.
        Returns:
        true if signature is valid.
        Throws:
        java.security.NoSuchAlgorithmException - if the algorithm is not supported.
        java.security.InvalidKeyException - if the given key is inappropriate for initializing the specified algorithm.
      • createSignatureFor

        byte[] createSignatureFor​(java.lang.String algorithm,
                                  byte[] secretBytes,
                                  byte[] headerBytes,
                                  byte[] payloadBytes)
                           throws java.security.NoSuchAlgorithmException,
                                  java.security.InvalidKeyException
        Create signature for JWT header and payload.
        Parameters:
        algorithm - algorithm name.
        secretBytes - algorithm secret.
        headerBytes - JWT header.
        payloadBytes - JWT payload.
        Returns:
        the signature bytes.
        Throws:
        java.security.NoSuchAlgorithmException - if the algorithm is not supported.
        java.security.InvalidKeyException - if the given key is inappropriate for initializing the specified algorithm.
      • verifySignatureFor

        boolean verifySignatureFor​(java.lang.String algorithm,
                                   java.security.PublicKey publicKey,
                                   java.lang.String header,
                                   java.lang.String payload,
                                   byte[] signatureBytes)
                            throws java.security.NoSuchAlgorithmException,
                                   java.security.InvalidKeyException,
                                   java.security.SignatureException
        Verify signature for JWT header and payload.
        Parameters:
        algorithm - algorithm name.
        publicKey - algorithm public key.
        header - JWT header.
        payload - JWT payload.
        signatureBytes - JWT signature.
        Returns:
        true if signature is valid.
        Throws:
        java.security.NoSuchAlgorithmException - if the algorithm is not supported.
        java.security.InvalidKeyException - if the given key is inappropriate for initializing the specified algorithm.
        java.security.SignatureException
      • verifySignatureFor

        boolean verifySignatureFor​(java.lang.String algorithm,
                                   java.security.PublicKey publicKey,
                                   byte[] headerBytes,
                                   byte[] payloadBytes,
                                   byte[] signatureBytes)
                            throws java.security.NoSuchAlgorithmException,
                                   java.security.InvalidKeyException,
                                   java.security.SignatureException
        Verify signature for JWT header and payload using a public key.
        Parameters:
        algorithm - algorithm name.
        publicKey - the public key to use for verification.
        headerBytes - JWT header.
        payloadBytes - JWT payload.
        signatureBytes - JWT signature.
        Returns:
        true if signature is valid.
        Throws:
        java.security.NoSuchAlgorithmException - if the algorithm is not supported.
        java.security.InvalidKeyException - if the given key is inappropriate for initializing the specified algorithm.
        java.security.SignatureException
      • createSignatureFor

        byte[] createSignatureFor​(java.lang.String algorithm,
                                  java.security.PrivateKey privateKey,
                                  byte[] headerBytes,
                                  byte[] payloadBytes)
                           throws java.security.NoSuchAlgorithmException,
                                  java.security.InvalidKeyException,
                                  java.security.SignatureException
        Create signature for JWT header and payload using a private key.
        Parameters:
        algorithm - algorithm name.
        privateKey - the private key to use for signing.
        headerBytes - JWT header.
        payloadBytes - JWT payload.
        Returns:
        the signature bytes.
        Throws:
        java.security.NoSuchAlgorithmException - if the algorithm is not supported.
        java.security.InvalidKeyException - if the given key is inappropriate for initializing the specified algorithm.
        java.security.SignatureException - if this signature object is not initialized properly or if this signature algorithm is unable to process the input data provided.
      • verifySignatureFor

        @Deprecated
        boolean verifySignatureFor​(java.lang.String algorithm,
                                   byte[] secretBytes,
                                   byte[] contentBytes,
                                   byte[] signatureBytes)
                            throws java.security.NoSuchAlgorithmException,
                                   java.security.InvalidKeyException
        Deprecated.
        rather use corresponding method which takes header and payload as separate inputs
        Verify signature.
        Parameters:
        algorithm - algorithm name.
        secretBytes - algorithm secret.
        contentBytes - the content to which the signature applies.
        signatureBytes - JWT signature.
        Returns:
        true if signature is valid.
        Throws:
        java.security.NoSuchAlgorithmException - if the algorithm is not supported.
        java.security.InvalidKeyException - if the given key is inappropriate for initializing the specified algorithm.
      • createSignatureFor

        @Deprecated
        byte[] createSignatureFor​(java.lang.String algorithm,
                                  byte[] secretBytes,
                                  byte[] contentBytes)
                           throws java.security.NoSuchAlgorithmException,
                                  java.security.InvalidKeyException
        Deprecated.
        rather use corresponding method which takes header and payload as separate inputs
        Create signature.
        Parameters:
        algorithm - algorithm name.
        secretBytes - algorithm secret.
        contentBytes - the content to be signed.
        Returns:
        the signature bytes.
        Throws:
        java.security.NoSuchAlgorithmException - if the algorithm is not supported.
        java.security.InvalidKeyException - if the given key is inappropriate for initializing the specified algorithm.
      • verifySignatureFor

        @Deprecated
        boolean verifySignatureFor​(java.lang.String algorithm,
                                   java.security.PublicKey publicKey,
                                   byte[] contentBytes,
                                   byte[] signatureBytes)
                            throws java.security.NoSuchAlgorithmException,
                                   java.security.InvalidKeyException,
                                   java.security.SignatureException
        Deprecated.
        rather use corresponding method which takes header and payload as separate inputs
        Verify signature using a public key.
        Parameters:
        algorithm - algorithm name.
        publicKey - algorithm public key.
        contentBytes - the content to which the signature applies.
        signatureBytes - JWT signature.
        Returns:
        the signature bytes.
        Throws:
        java.security.NoSuchAlgorithmException - if the algorithm is not supported.
        java.security.InvalidKeyException - if the given key is inappropriate for initializing the specified algorithm.
        java.security.SignatureException - if this signature object is not initialized properly or if this signature algorithm is unable to process the input data provided.
      • createSignatureFor

        @Deprecated
        byte[] createSignatureFor​(java.lang.String algorithm,
                                  java.security.PrivateKey privateKey,
                                  byte[] contentBytes)
                           throws java.security.NoSuchAlgorithmException,
                                  java.security.InvalidKeyException,
                                  java.security.SignatureException
        Deprecated.
        rather use corresponding method which takes header and payload as separate inputs
        Create signature using a private key.
        Parameters:
        algorithm - algorithm name.
        privateKey - the private key to use for signing.
        contentBytes - the content to be signed.
        Returns:
        the signature bytes.
        Throws:
        java.security.NoSuchAlgorithmException - if the algorithm is not supported.
        java.security.InvalidKeyException - if the given key is inappropriate for initializing the specified algorithm.
        java.security.SignatureException - if this signature object is not initialized properly or if this signature algorithm is unable to process the input data provided.