Hi!
I have a problem with my GemSafe "Smart Card" and Java 1.5. I've developed a program that signs a document, every thing seems to be fine, but when I try to verify the signature a "Signature encoding error" is thrown. If we change the line:
Signature verify = Signature.getInstance("SHA1withRSA");
using:
Signature verify = Signature.getInstance("SHA1withRSA", pkcs11Provider);
The verification status is "OK"! But it has no sense to use that provider in the server!
What's wrong? I cannot continue :'(
Many thanks.
Here is the sample code:
import java.io.*;
import java.util.*;
import java.security.*;
import java.security.cert.*;
public class PatoFirma {
public static void main (String args[]) {
try {
PatoFirma pf=new PatoFirma ();
pf.go();
}
catch (Exception ex) {
ex.printStackTrace();
}
}
public void go () throws Exception {
// Provider.
Provider pkcs11Provider = new sun.security.pkcs11.SunPKCS11("c:/cardConfig.txt");
// Access to the smart card.
char[] pin = "1234".toCharArray();
KeyStore keyStore = KeyStore.getInstance("PKCS11", pkcs11Provider);
keyStore.load(null, pin);
// Get the first alias in the smart card.
Enumeration aliasesEnum = keyStore.aliases();
String alias = (String) aliasesEnum.nextElement();
// Use this sample doc:
byte[] doc = "pato".getBytes();
// Sign.
Signature signatureAlgorithm = Signature.getInstance("SHA1withRSA", pkcs11Provider);
signatureAlgorithm.initSign((PrivateKey) keyStore.getKey(alias, null));
signatureAlgorithm.update(doc);
byte[] digitalSignature = signatureAlgorithm.sign();
// Verify.
Signature verify = Signature.getInstance("SHA1withRSA");
verify.initVerify(keyStore.getCertificate(alias));
verify.update(doc);
boolean flag = verify.verify(digitalSignature);
System.out.println("-->" + (flag ? "TRUE":"FALSE"));
}
}