pkey.getEncoded() returns a SubjectPublicKeyInfo. fromRaw() expects just
the public key. Try this:

import org.mozilla.jss.pkix.primitive.SubjectPublicKeyInfo;
[...]
byte[] spkiEncoded = pkey.getEncoded();
SubjectPublicKeyInfo spki = (SubjectPublicKeyInfo)
SubjectPublicKeyInfo.getTemplate().decode(spkiEncoded);
org.mozilla.jss.pkcs11.PK11PubKey zubkey =
org.mozilla.jss.pkcs11.PK11PubKey.fromRaw(
     org.mozilla.jss.crypto.PrivateKey.Type.RSA,
     spki.getSubjectPublicKey().getBits() );


Reply via email to