Microsoft CryptoAPI: how to convert PUBLICKEYBLOB to DER/PEM?

后端 未结 2 1539
逝去的感伤
逝去的感伤 2021-01-27 08:19

I have a generated RSA key pair stored as PRIVATEKEYBLOB and PUBLICKEYBLOB, and I need to be able to convert these keys to DER or PEM formats so I could use it in PHP or Python.

相关标签:
2条回答
  • 2021-01-27 08:59

    I struggled with PUBLICKEYBLOB -> PEM/DER formats until I found a post about pulling one from a smart card and converting it. The gist of it is, MS PUBLICKEYBLOB needs to have the first 32 bytes removed, then reverse the order and add 02 03 01 00 01 to the end. That will give you DER format. You can then base64 encode to get PEM and then add the requisite begin/end public key lines.

    You can refer to the original post for background.

    0 讨论(0)
  • 2021-01-27 09:02

    Use RSA_CSP_PUBLICKEYBLOB as documented in https://msdn.microsoft.com/en-us/library/windows/desktop/aa378145(v=vs.85).aspx

    0 讨论(0)
提交回复
热议问题