本文介绍了"BEGIN RSA PRIVATE KEY"之间的区别和"BEGIN私钥";的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个程序,该程序从.pem文件导入私钥并创建一个私钥对象以供以后使用.我面临的问题是某些pem文件头以

Hi I was writing a program that imports private keys from a .pem file and create a private key object to use it later..the problem I have faced is that some pem files header begin with

-----BEGIN PRIVATE KEY-----

而其他人以

-----BEGIN RSA PRIVATE KEY-----

通过搜索,我知道第一个是PKCS#8格式,但是我不知道另一个属于什么格式.

through my search I knew that the first ones are PKCS#8 formatted but I couldn't know what format does the other one belongs to.

推荐答案

请参见 https://polarssl.org/kb/cryptography/asn1-key-structures-in-der-pem (在页面上搜索"BEGIN RSA PRIVATE KEY")(存档链接以防万一,以防万一.)

See https://polarssl.org/kb/cryptography/asn1-key-structures-in-der-and-pem (search the page for "BEGIN RSA PRIVATE KEY") (archive link for posterity, just in case).

BEGIN RSA PRIVATE KEY是PKCS#1,仅是RSA密钥.从本质上讲,它只是PKCS#8中的关键对象,但前面没有版本或算法标识符. BEGIN PRIVATE KEY是PKCS#8,它指示密钥类型本身包含在密钥数据中.从链接:

BEGIN RSA PRIVATE KEY is PKCS#1 and is just an RSA key. It is essentially just the key object from PKCS#8, but without the version or algorithm identifier in front. BEGIN PRIVATE KEY is PKCS#8 and indicates that the key type is included in the key data itself. From the link:

-----BEGIN PRIVATE KEY-----
BASE64 ENCODED DATA
-----END PRIVATE KEY-----

在base64编码的数据中,存在以下DER结构:

Within the base64 encoded data the following DER structure is present:

PrivateKeyInfo ::= SEQUENCE {
  version         Version,
  algorithm       AlgorithmIdentifier,
  PrivateKey      BIT STRING
}

AlgorithmIdentifier ::= SEQUENCE {
  algorithm       OBJECT IDENTIFIER,
  parameters      ANY DEFINED BY algorithm OPTIONAL
}

因此,对于RSA私钥,OID为1.2.840.113549.1.1.1,并且有一个RSAPrivateKey作为私钥密钥数据位串.

So for an RSA private key, the OID is 1.2.840.113549.1.1.1 and there is a RSAPrivateKey as the PrivateKey key data bitstring.

BEGIN RSA PRIVATE KEY相对,后者始终指定RSA密钥,因此不包括密钥类型OID. BEGIN RSA PRIVATE KEYPKCS#1:

As opposed to BEGIN RSA PRIVATE KEY, which always specifies an RSA key and therefore doesn't include a key type OID. BEGIN RSA PRIVATE KEY is PKCS#1:

RSA专用密钥PEM文件专用于RSA密钥.

The RSA private key PEM file is specific for RSA keys.

它以标签开头和结尾:

-----BEGIN RSA PRIVATE KEY-----
BASE64 ENCODED DATA
-----END RSA PRIVATE KEY-----

在base64编码的数据中,存在以下DER结构:

Within the base64 encoded data the following DER structure is present:

RSAPrivateKey ::= SEQUENCE {
  version           Version,
  modulus           INTEGER,  -- n
  publicExponent    INTEGER,  -- e
  privateExponent   INTEGER,  -- d
  prime1            INTEGER,  -- p
  prime2            INTEGER,  -- q
  exponent1         INTEGER,  -- d mod (p-1)
  exponent2         INTEGER,  -- d mod (q-1)
  coefficient       INTEGER,  -- (inverse of q) mod p
  otherPrimeInfos   OtherPrimeInfos OPTIONAL
}

这篇关于"BEGIN RSA PRIVATE KEY"之间的区别和"BEGIN私钥";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 12:40