no such algorithm: SHA-1 for provider BC
843811Apr 21 2006 — edited Apr 24 2006�m trying to verify a signature made in Firefox with
windows.crypto.signText and the same text signed in Internet Explorer
with Capicom.
My problem is in Tomcat when I try validate this signature.
I always obtain a "NoSuchAlgorithmException", my code is very simple.
Code is not perfect, but it was only a first version.
Can somebody tell me why I obtain that error? What is wrong in my code?
verifySignature(HttpServletRequest request, PrintWriter out)
{
Object o = request.getAttribute("javax.servlet.request.X509Certificate");
X509Certificate[] certs = (X509Certificate[]) o;
X509Certificate cert;
if ( certs.length>0)
{
cert = certs[0];
Signature signature;
try
{
//Add the providir, perhaps not necesary
Security.addProvider(new BouncyCastleProvider());
//Set provider for signature, perhaps not necesary
signature = Signature.getInstance("SHA-1",new BouncyCastleProvider());
signature.initVerify(cert);
signature.update(request.getParameter("textoToSign").getBytes());
if (signature.verify(request.getParameter("firma").getBytes()))
{
out.print("**********OK******************");
}
else
{
out.print("---------------NOT OK-------------");
}
}
catch(Exception e)
{
out.print("ERROR: " + e.getMessage());
e.printStackTrace();
return;
}
}//end if
}//end function
The result is always
ERROR: no such algorithm: SHA-1 for provider BC
I have tryed without specify provide and with
gnu.crypto.jce.GnuCrypto() (GNU Cryto Provider) and the result is the
same.
Thanks in advance.