The problem is that the Java code doesn't support an DER encoded key.
From mozilla/security/nss/lib/softoken/pkcs11.c in NSS:
/* special note: We can't just use the first byte to determine
* between these 2 cases because both EC_POINT_FORM_UNCOMPRESSED
* and SEC_ASN1_OCTET_STRING are 0x04 */
/* handle the non-DER encoded case (UNCOMPRESSED only) */
if (pubKey->u.ec.publicValue.data[0] == EC_POINT_FORM_UNCOMPRESSED
&& pubKey->u.ec.publicValue.len == keyLen) { break; /* key was not DER encoded, no need to unwrap */
}
/* if we ever support compressed, handle it here */
/* handle the encoded case */
if ((pubKey->u.ec.publicValue.data[0] == SEC_ASN1_OCTET_STRING)
&& pubKey->u.ec.publicValue.len > keyLen) {
SECItem publicValue; SECStatus rv;
The problem is that the Java code doesn't support an DER encoded key. security/ nss/lib/ softoken/ pkcs11. c in NSS:
From mozilla/
/* special note: We can't just use the first byte to determine FORM_UNCOMPRESS ED OCTET_STRING are 0x04 */
* between these 2 cases because both EC_POINT_
* and SEC_ASN1_
/* handle the non-DER encoded case (UNCOMPRESSED only) */ >u.ec.publicVal ue.data[ 0] == EC_POINT_ FORM_UNCOMPRESS ED >u.ec.publicVal ue.len == keyLen) {
break; /* key was not DER encoded, no need to unwrap */
if (pubKey-
&& pubKey-
}
/* if we ever support compressed, handle it here */
/* handle the encoded case */ >u.ec.publicVal ue.data[ 0] == SEC_ASN1_ OCTET_STRING) >u.ec.publicVal ue.len > keyLen) {
SECStatus rv;
if ((pubKey-
&& pubKey-
SECItem publicValue;
rv = SEC_QuickDERDec odeItem( arena, &publicValue,
SEC_ ASN1_GET( SEC_OctetString Template) ,
& pubKey- >u.ec.publicVal ue);
| | (publicValue. data[0] != EC_POINT_ FORM_UNCOMPRESS ED)
| | (publicValue.len != keyLen)) {
crv = CKR_ATTRIBUTE_ VALUE_INVALID;
break;
pubKey- >u.ec.publicVal ue = publicValue;
break;
/* nope, didn't decode correctly */
if ((rv != SECSuccess)
}
/* replace our previous with the decoded key */
}