在 mac 的终端中将 pem 格式的 public 密钥转换为 der 格式时出错

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

我在 mac 中使用终端为 SSL 连接创建了 public 私钥对。我使用以下命令创建私钥并从中提取 public 密钥:

# 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

现在要在我的 iPhone 应用程序中使用 public 密钥,我需要将其转换为 der 格式。但是当我尝试使用以下命令转换它时出现错误:

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**

我正在使用 this link 与服务器建立 SSL 连接。

我认为将 public 密钥从 PEM 格式转换为 DER 格式的命令是

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

(您选择的输出文件名 cert.der 具有误导性。它是 public 密钥,而不是证书,public.der 会更好)