📅  最后修改于: 2023-12-03 15:03:23.118000             🧑  作者: Mango
OpenSSL is a widely used toolkit to provide SSL/TLS and cryptographic functions to applications. One of its utilities is the ability to convert a public key from DER format to PEM format.
DER (Distinguished Encoding Rules) is a binary format used to store public or private keys in ASN.1 (Abstract Syntax Notation One) data structures. DER is a compact, deterministic and standardized format, which makes it useful for transmitting keys over the internet.
PEM (Privacy Enhanced Mail) is a text format that uses base64 encoding to store public or private keys. PEM is a human-readable and platform-independent format, which makes it widely used in applications.
Using OpenSSL, you can easily convert a public key from DER to PEM format with the following command:
$ openssl rsa -inform der -in publickey.der -pubin -outform pem -out publickey.pem
Let's break down this command:
openssl rsa
: This command is used to manipulate RSA keys.-inform der
: This option specifies that the input key is in DER format.-in publickey.der
: This option specifies the input file.-pubin
: This option specifies that the input key is a public key.-outform pem
: This option specifies that the output key should be in PEM format.-out publickey.pem
: This option specifies the output file.Once executed, the public key in DER format will be converted to PEM format and saved in publickey.pem
.
In this article, we have explained what DER and PEM formats are, and how to convert a public key from DER to PEM using OpenSSL. This conversion is useful when dealing with applications that require keys to be in PEM format.