简体   繁体   中英

Error while converting public key in pem format to der format in terminal in mac

I have created public private key pair for SSL connection using terminal in mac. I have used following commands to create private key and extracting public key from it:

# Create public-private key pair
openssl genrsa -out mykey.cer 1024

# Extract public key
openssl rsa -in mykey.cer -out public.pem -outform PEM -pubout

Now to use public key in my iPhone app I need to convert it to der format. But when I try to convert it with following command I am getting an error:

openssl x509 -in public.pem -outform der -out cert.der
**unable to load certificate
27928:error:0906D06C:PEM routines:PEM_read_bio:no start line:/SourceCache/OpenSSL098/OpenSSL098-52.20.2/src/crypto/pem/pem_lib.c:648:Expecting: TRUSTED CERTIFICATE**

I am using this link to create a SSL connection with server.

I believe the command to convert a public key from PEM to DER format is

openssl rsa -pubin -in public.pem -outform der -out cert.der

(your choice of output filename cert.der is misleading. It's a public key, not a certificate, public.der would be better)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM