-1

I have created EC key pair in HSM using PKCS11Interop library, and i need to create PKCS10 Certificate request using this keys. For generation of PKCS10 I use BC, and in this situation i need to set public key as a parameter for PKCS10 request. In BC i need to get public key as ECPublicKeyParameters for putting in PKCS10 object. I do not know how to map PKCS11 public key to ECPublicKeyParameters.

Or may be there is another method for this type mapping?

Thanks in advance!

Uzeyir
  • 1
  • 1

1 Answers1

0
import org.bouncycastle.crypto.params.AsymmetricKeyParameter;
import org.bouncycastle.crypto.util.PublicKeyFactory;

AsymmetricKeyParameter keyParameters = PublicKeyFactory.createKey(publicKey.getEncoded());
if (keyParameters instanceof ECPublicKeyParameters) {
    ECPublicKeyParameters ecPublicKeyParameters = (ECPublicKeyParameters) keyParameters;


}
Egl
  • 774
  • 7
  • 20
  • Thanks for your answer. Which attributes of pkcs11 public key must be used in yor code? I can get cka_ec_params, cka_ec_point from pkcs11 pub key. from these attributes how can i create a correct ecpublickeyparameters of BC? – Uzeyir Dec 03 '19 at 18:10
  • I thought you already had a PublicKey object from your key pair generation. This is the publicKey object in my code. That's all.The call to PublicKeyFactory.createKey() already generates the ECPublicKeyParameters object. – Egl Dec 30 '19 at 18:15