public static String sign(String signingString,PrivateKey privateKey) throws InvalidKeyException, SignatureException {
  byte[] bytes=signingString.getBytes(StandardCharsets.UTF_8);
  Signature sig;
  try {
    sig=Signature.getInstance(SHA256_WITH_RSA);
  }
 catch (  NoSuchAlgorithmException e) {
    throw new IllegalArgumentException("An error occurred while getting the signature algorithm",e);
  }
  sig.initSign(privateKey);
  sig.update(bytes);
  return Hex.encodeHexString(sig.sign());
}

public static String sign ( String signingString , PrivateKey privateKey ) throws InvalidKeyException , SignatureException { byte [ ] bytes = signingString . getBytes ( StandardCharsets . UTF_8 ) ; Signature sig ; try { sig = Signature . getInstance ( SHA256_WITH_RSA ) ; } catch ( NoSuchAlgorithmException e ) { throw new IllegalArgumentException ( "An error occurred while getting the signature algorithm" , e ) ; } sig . initSign ( privateKey ) ; sig . update ( bytes ) ; return Hex . encodeHexString ( sig . sign ( ) ) ; }
signs a string using the private key and sha 256 with rsa signing algorithm , and returns it as a hex - encoded string .
