How to save public key from a certificate in .pem format

后端 未结 2 1302
傲寒
傲寒 2020-12-02 05:37

I am using the below openssl command for storing my public key into a .pem file.

openssl> x509 -in E:/mycert.pem -pubkey  -out E:/mypubkey.pem


        
相关标签:
2条回答
  • 2020-12-02 05:53

    if it is a RSA key

    openssl rsa  -pubout -in my_rsa_key.pem
    

    if you need it in a format for openssh , please see Use RSA private key to generate public key?

    Note that public key is generated from the private key and ssh uses the identity file (private key file) to generate and send public key to server and un-encrypt the encrypted token from the server via the private key in identity file.

    0 讨论(0)
  • 2020-12-02 06:12

    There are a couple ways to do this.

    First, instead of going into openssl command prompt mode, just enter everything on one command line from the Windows prompt:

    E:\> openssl x509 -pubkey -noout -in cert.pem  > pubkey.pem
    

    If for some reason, you have to use the openssl command prompt, just enter everything up to the ">". Then OpenSSL will print out the public key info to the screen. You can then copy this and paste it into a file called pubkey.pem.

    openssl> x509 -pubkey -noout -in cert.pem
    

    Output will look something like this:

    -----BEGIN PUBLIC KEY-----
    MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAryQICCl6NZ5gDKrnSztO
    3Hy8PEUcuyvg/ikC+VcIo2SFFSf18a3IMYldIugqqqZCs4/4uVW3sbdLs/6PfgdX
    7O9D22ZiFWHPYA2k2N744MNiCD1UE+tJyllUhSblK48bn+v1oZHCM0nYQ2NqUkvS
    j+hwUU3RiWl7x3D2s9wSdNt7XUtW05a/FXehsPSiJfKvHJJnGOX0BgTvkLnkAOTd
    OrUZ/wK69Dzu4IvrN4vs9Nes8vbwPa/ddZEzGR0cQMt0JBkhk9kU/qwqUseP1QRJ
    5I1jR4g8aYPL/ke9K35PxZWuDp3U0UPAZ3PjFAh+5T+fc7gzCs9dPzSHloruU+gl
    FQIDAQAB
    -----END PUBLIC KEY-----
    
    0 讨论(0)
提交回复
热议问题