byte [ ] createSignatureFor ( String algorithm , byte [ ] secretBytes , byte [ ] headerBytes , byte [ ] payloadBytes ) throws NoSuchAlgorithmException , InvalidKeyException { final Mac mac = Mac . getInstance ( algorithm ) ; mac . init ( new SecretKeySpec ( secretBytes , algorithm ) ) ; mac . update ( headerBytes ) ; mac . update ( JWT_PART_SEPARATOR ) ; return mac . doFinal ( payloadBytes ) ; }
Create signature for JWT header and payload .