September 15, 2016

Java Supported Signature Algorithms

Reference https://docs.oracle.com/javase/8/docs/technotes/guides/security/StandardNames.html#Signature

Java Code Example

public byte[] generateSignature(PrivateKey privateKey, String data) throws NoSuchAlgorithmException,
        NoSuchProviderException, InvalidKeyException, SignatureException, UnsupportedEncodingException {

    Signature signature = Signature.getInstance("SHA1withRSA");
    signature.initSign(privateKey);
    signature.update(data.getBytes("UTF-8"));
    return signature.sign();
}

No comments: