How to Convert RSA keys from .pem to .der and vice versa by using psa in nrf52840

Hello,

I am trying to convert .pem RSA keys which we are getting externally into .der and vice versa, because in "psa_import_key" function we can only use in keys .der format.

I am using ncs-2.6.0 version

Board: nrf52840

Please guide us how can I convert .pem to .der or directly use .pem keys?

Is there any library which we can directly use to convert it because we are using PSA??

Parents
  • Hi,

    Do you need to do it on target, or can you do it using openssl x509 or similar? On target, it could be done using mbedtls_pk_parse_key() and then mbedtls_pk_import_into_psa() for newer SDK versions, but not 2.6 (as described here).

  • Hello,

    I am using "mbedtls_pk_parse_public_key" function and then "mbedtls_pk_write_pubkey_der" this function but how can i enable these two function definition in my target? by enabling which macro we can do that?

  • Hi,

    I have checked this a bi tmore, and this is unfortunately far from staright-forward. If possible, it would be better and much simpler to do conversion to/from PEM externally and only import raw keys to the nRF (and the same if you need to export keys).

    For instance, if you have a private key in PEM format, you can convert it to a raw key like this using openssl:

    Fullscreen
    1
    openssl rsa -inform PEM -outform DER -in <infilename> -out <outfilename>
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Reply
  • Hi,

    I have checked this a bi tmore, and this is unfortunately far from staright-forward. If possible, it would be better and much simpler to do conversion to/from PEM externally and only import raw keys to the nRF (and the same if you need to export keys).

    For instance, if you have a private key in PEM format, you can convert it to a raw key like this using openssl:

    Fullscreen
    1
    openssl rsa -inform PEM -outform DER -in <infilename> -out <outfilename>
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Children
No Data