byte [ ] createSignatureFor ( String algorithm , PrivateKey privateKey , byte [ ] headerBytes , byte [ ] payloadBytes ) throws NoSuchAlgorithmException , InvalidKeyException , SignatureException { final Signature s = Signature . getInstance ( algorithm ) ; s . initSign ( privateKey ) ; s . update ( headerBytes ) ; s . update ( JWT_PART_SEPARATOR ) ; s . update ( payloadBytes ) ; return s . sign ( ) ; }
Create signature for JWT header and payload using a private key .