Java Requires Chilkat v11.0.0+
Chilkat2 Java
RSASSA-PSS Algorithm with SHA256 Hashing
See more RSA Examples
RSA encrypt a SHA256 hash with OAEP padding.Chilkat Java Downloads
import com.chilkatsoft.chilkat2.ChilkatException;
import com.chilkatsoft.chilkat2.PrivateKey;
import com.chilkatsoft.chilkat2.Rsa;
public class ChilkatExample {
public static void main(String[] args) {
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
PrivateKey privkey = new PrivateKey();
// Load the private key object from a PEM file.
// (To load from a PEM string, call LoadPem instead.)
try {
privkey.loadPemFile("somePath/myPrivateKey.pem");
} catch (ChilkatException e) {
System.out.println(e.getLastErrorText());
return;
}
Rsa rsa = new Rsa();
// Use RSA-PSS by setting PkcsPadding = false
rsa.setPkcsPadding(false);
// Use SHA256
rsa.setOaepHash("SHA-256");
rsa.usePrivateKey(privkey);
// Generate a base64 signature.
rsa.setEncodingMode("base64");
String sigStr;
try {
sigStr = rsa.signStringENC("String to be signed", "SHA-256");
} catch (ChilkatException e) {
System.out.println(e.getLastErrorText());
return;
}
System.out.println("Signature: " + sigStr);
}
}