@Test public void shouldValidateTheSHA1WithRSASignature() throws Exception {

    // create a public/private key pair
    KeyFactory keyFactory   = KeyFactory.getInstance("RSA");
    KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA");
    KeyPair pair = keyGen.generateKeyPair();
    EncodedKeySpec encoded = new X509EncodedKeySpec(pair.getPublic().getEncoded());
    PublicKey encodedPublic = keyFactory.generatePublic(encoded);
    String encodePublicBase64 = Base64.encodeToString(encodedPublic.getEncoded(), Base64.DEFAULT);
    // and sign some data with it
    Signature sig = Signature.getInstance("SHA1WithRSA");
    sig.initSign(pair.getPrivate());
    String data = "some sample data";
    sig.update(data.getBytes());
    String signature = Base64.encodeToString(sig.sign(), Base64.DEFAULT);
    SignatureValidator validator = new DefaultSignatureValidator(encodePublicBase64);
    assertThat(validator.validate(data, signature)).isTrue();
    assertThat(validator.validate(data+"extraData", signature)).isFalse();
}