MD2withRSA
This Signature class implements the algorithm “MD2withRSA” as defined in PKCS#1. This algorithm will perform a message digest of the data to be signed, encode that information in a X.509 DigestInfo block, and then RSA encrypt the DER-encoded block.
Initialization requires a SafeNet ProtectToolkit-J RSA key, either a private key for signing or a public key for signature verification. See the RSA Cipher (RSA) for information on RSA keys.
This algorithm is provided for compatibility only; newer applications should use either MD5withRSA or SHA1withRSA.
The following example will sign the message “hello world” with a pre-existing RSA private key, and then verify it with the corresponding public key.
KeyPair rsaPair; // pre existing key pair
Signature rsaSig = Signature.getInstance(“MD2withRSA”, “SAFENET”);
rsaSig.initSign(rsaPair.getPrivate());
rsaSig.update(“hello world”.getBytes());
byte[] sig = rsaSig.sign();
rsaSig.initVerify(rsaPair.getPublic());
rsaSig.update(“hello world”.getBytes());
if (rsaSig.verify(sig)) {
System.out.println(“Signature okay”);
} else {
System.out.println(“Signature fails verification”);
}