List Info

Thread: InvalidKeyException: Neither a public nor a private key




InvalidKeyException: Neither a public nor a private key
country flaguser name
United States
2007-02-07 04:50:31
Good Day All,

I'm having problem to develop a sample signature
application.

I can load the keystore and extract its objects
(certificates, public key
and private key) but when i try to sign something, is thrown
an exception
InvalidKeyException

i'm using de code below

p = new PKCS11Provider("dkck201.dll");
//p = new PKCS11Provider("eTpkcs11.dll");
Security.addProvider(p);
lps = PKCS11Slot.enumerateSlots(p);
p11Session = null;
String senha = null;
BufferedReader input = new BufferedReader(new
InputStreamReader(System.in));
for (Iterator<PKCS11Slot> iter = lps.iterator();
iter.hasNext()) {
	p11Slot = iter.next();
	b = p11Slot.isTokenPresent();
	if (b) {
		System.out.println(p11Slot.getTokenSerialNumber());
		p11Session = PKCS11Session.open(p11Slot,
				PKCS11Session.OPEN_MODE_READ_ONLY);
		senha = input.readLine();
		p11Session.loginUser(senha.toCharArray());
		List<PKCS11PrivateKey> pkeys = PKCS11PrivateKey
				.getPrivateKeys(p11Session);
		byte[] sb = null;
		for (PKCS11PrivateKey key : pkeys) {
			Signature s =
Signature.getInstance("SHA1WithRSA");
			s.initSign(key);
			s.update("teste".getBytes());
			sb = s.sign();
			System.out.println(new String(sb));
		}
	}
}

Thanks in advance
De La Croix
-- 
View this message in context: http://ww
w.nabble.com/InvalidKeyException%3A-Neither-a-public-nor-a-p
rivate-key-tf3186197.html#a8843270
Sent from the OpenSC - User mailing list archive at
Nabble.com.

_______________________________________________
opensc-user mailing list
opensc-userlists.opensc-project.org
http://www.opensc-project.org/mailman/listinfo/opensc-
user

[1]

about | contact  Other archives ( Real Estate discussion Medical topics )