net.loginbuddy.common/src/main/java/net/loginbuddy/common/util/Jwt.java
/**
     * Create a JWS. The secret will be used with HMAC-SHA256. The content may represent a JSON structure but maybe not.
     *
     * @param secret  The secret used to create the signature. MUST be at least 256bit long!
     * @param content The content that becomes the payload
     * @return The JWS object or null if something went wrong
     */
Create a JWS. The secret will be used with HMAC-SHA256. The content may represent a JSON structure but maybe not.
@param secret  The secret used to create the signature. MUST be at least 256bit long.
@param content The content that becomes the payload
@return The JWS object or null if something went wrong
Create a JWS . The secret will be used with HMAC - SHA256 . The content may represent a JSON structure but maybe not . @param secret The secret used to create the signature . MUST be at least 256bit long . @param content The content that becomes the payload @return The JWS object or null if something went wrong
public JsonWebSignature createSignedJwtHs256(byte[] secret, String content) {
        try {
            JsonWebSignature jws = new JsonWebSignature();
            jws.setAlgorithmHeaderValue(AlgorithmIdentifiers.HMAC_SHA256);
            jws.setHeader("typ", "JWT");
            jws.setPayload(content);
            SecretKeySpec key = new SecretKeySpec(secret, AlgorithmIdentifiers.HMAC_SHA256);
            jws.setKey(key);
            return jws;
        } catch (Exception e) {
            LOGGER.warning("The JWT could not be created!");
            e.printStackTrace();
        }
        return null;
    }
public JsonWebSignature createSignedJwtHs256 ( byte [ ] secret , String content ) { try { JsonWebSignature jws = new JsonWebSignature ( ) ; jws . setAlgorithmHeaderValue ( AlgorithmIdentifiers . HMAC_SHA256 ) ; jws . setHeader ( "typ" , "JWT" ) ; jws . setPayload ( content ) ; SecretKeySpec key = new SecretKeySpec ( secret , AlgorithmIdentifiers . HMAC_SHA256 ) ; jws . setKey ( key ) ; return jws ; } catch ( Exception e ) { LOGGER . warning ( "The JWT could not be created!" ) ; e . printStackTrace ( ) ; } return null ; }
Create a JWS.
Create a JWS .