I'm trying to interplate and implement the following statement.
Digitally sign the payload with Private Key using RSASSA-PKCS1-V1_5 signature scheme and SHA1 cryptographic hash function.
Note: Refer to PKCS #1 v2.1: RSA Cryptography Standard specification for PKCS1-v1.5 Signature and Encryption scheme.
I'm confused when it says "and" sha1 hash function, below is adopted code which i'm not sure if it the right interpretation
public String getSignature(String _plainTextMessage,PrivateKey privateKey){
try {
Signature signer = Signature.getInstance("SHA1withRSA");
signer.initSign(privateKey);
signer.update(_plainTextMessage.getBytes());
byte[] signature = signer.sign();
return new BASE64Encoder().encode(signature);
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (InvalidKeyException e) {
e.printStackTrace();
} catch (SignatureException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
or do i need to include MessageDiget like below
public String getSignature(String _plainTextMessage,PrivateKey privateKey){
try {
Signature signer = Signature.getInstance("SHA1withRSA");
signer.initSign(privateKey);
signer.update(_plainTextMessage.getBytes());
byte[] signature = signer.sign();
MessageDigest sha1 = MessageDigest.getInstance("SHA1");
byte[] digest = sha1.digest(signature);
return new BASE64Encoder().encode(digest);
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (InvalidKeyException e) {
e.printStackTrace();
} catch (SignatureException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
I will appreciate any hint, and if applicable how do i verify the signature if i use the second option.
thanks