public static byte[] signMessage(RSAPrivateKey key, byte[] message, String signAlgo)
            throws NoSuchAlgorithmException, InvalidKeyException, SignatureException {
        if (StringUtils.isBlank(signAlgo)) {
            signAlgo = DEFAULT_SIGNATURE_ALGORITHM;
        }
        Signature sign = Signature.getInstance(signAlgo);
        sign.initSign(key, SECURE_RNG);
        sign.update(message);
        return sign.sign();
    }
public static byte [ ] signMessage ( RSAPrivateKey key , byte [ ] message , String signAlgo ) throws NoSuchAlgorithmException , InvalidKeyException , SignatureException { if ( StringUtils . isBlank ( signAlgo ) ) { signAlgo = DEFAULT_SIGNATURE_ALGORITHM ; } Signature sign = Signature . getInstance ( signAlgo ) ; sign . initSign ( key , SECURE_RNG ) ; sign . update ( message ) ; return sign . sign ( ) ; }
Sign a message with RSA private key.

@param key
@param message
the message to sign
@param signAlgo
signature algorithm to use. If empty, {@link #DEFAULT_SIGNATURE_ALGORITHM} will be
used.
@return the signature
@throws NoSuchAlgorithmException
@throws InvalidKeyException
@throws SignatureException