The following Java encryption example uses the Spongy Castle library.

Sign data

Signing data using RSA private key with PKCS1 v1.5 padding and SHA256 hash:

private byte[] signWithPrivateKey(byte[] bytes, String privateKey) throws Exception {
    Signature signature = Signature.getInstance("SHA256withRSA", "SC");
    return signature.sign();

Verify signature

Decrypt a package using RSA private key with PKCS1-OAEP padding:

public static boolean verifySignature(String publicKeyIn, byte[] signatureIn, byte[] data) throws Exception {
       PublicKey publicKey = getRSAPublicKeyFromString(publicKeyIn);
       Signature signature = Signature.getInstance("SHA256withRSA", "BC");
       return signature.verify(signatureIn);

User Contributed

LaunchKey links to user contributed code as a resource to its community. LaunchKey does not in any way guarantee or warrant the quality and security of these code bases. User contributed code is supported by the creators. If you do find a link from the site to user contributed code that is malicious or inappropriate in any way, please report that link to LaunchKey immediately and we will investigate the claim. Submit any issue to LaunchKey support at ×