public String sign ( String msg ) { try { RSAPrivateKey key = getPrivateKey ( ) ; Signature sig = Signature . getInstance ( SIGNING_ALGORITHM + "with" + key . getAlgorithm ( ) ) ; sig . initSign ( key ) ; sig . update ( msg . getBytes ( StandardCharsets . UTF_8 ) ) ; return hudson . remoting . Base64 . encode ( sig . sign ( ) ) ; } catch ( GeneralSecurityException e ) { throw new SecurityException ( e ) ; } }
Sign a message and base64 encode the signature .