Click here to Skip to main content
15,889,909 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hello

I have an application to sign with file .cer and .key, but when I try to validate the sign with only certificate file

This is the code in Java

public static String verifySign(String cerPath, String toVerify, String sign) {
String resultado = null;
Boolean blnResultado = false;
try (InputStream cer = new FileInputStream(new File(cerPath))) {
CertificateFactory cf = CertificateFactory.getInstance("X.509");
Certificate cert = (X509Certificate) cf.generateCertificates(cer).iterator().next();

final Signature signature = Signature.getInstance("SHA256withRSA");
signature.initVerify(cert.getPublicKey());
signature.update(toVerify.getBytes("UTF-8"));

blnResultado = signature.verify(Base64.decodeBase64(sign.getBytes("UTF-8")));

} catch (Exception e) {
e.printStackTrace();

}
if(blnResultado.equals(Boolean.FALSE)) {
resultado = new String("Firma Incorrecta");
} else {
resultado = new String("Firma Correcta");
}
return resultado;
}

What I have tried:

I try to do the same thing in C# and I try to find other ways to verify signature generated by my application.
Posted
Updated 8-Oct-18 6:08am

1 solution

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900