📜  openssl public key der to pem - 汇编(1)

📅  最后修改于: 2023-12-03 15:03:23.118000             🧑  作者: Mango

OpenSSL public key DER to PEM

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.

What is DER 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.

What is PEM format?

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.

How to convert a public key from DER to PEM?

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.

Conclusion

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.