Java Requires Chilkat v11.0.0+
Chilkat2 Java
RSA Sign utf-8 Byte Representation of String
See more RSA Examples
Demontstrates how to sign the utf-8 byte representation of a string.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.
// Load an RSA private key for signing.
PrivateKey privKey = new PrivateKey();
try {
privKey.loadEncryptedPemFile("qa_data/pem/rsa_passwd.pem", "passwd");
} catch (ChilkatException e) {
System.out.println(e.getLastErrorText());
return;
}
Rsa rsa = new Rsa();
try {
rsa.usePrivateKey(privKey);
} catch (ChilkatException e) {
System.out.println(e.getLastErrorText());
return;
}
String originalData = "This is the string to be hashed an RSA signed.";
// Indicate that we want the utf-8 byte representation of the string to be signed
rsa.setCharset("utf-8");
// We want the RSA signature in base64 format
rsa.setEncodingMode("base64");
String sigBase64 = rsa.signStringENC(originalData, "sha256");
System.out.println(sigBase64);
}
}