简体   繁体   English

在没有SSL封装头的情况下读取Base64私钥

[英]Read Base64 private key without encapsulation header in OpenSSL

I am trying to decrypt a message using a private key with openssl. 我正在尝试使用带有openssl的私钥解密消息。 My implementation works fine when i use the private key in the following format 当我以以下格式使用私钥时,我的实现工作正常

-----BEGIN RSA PRIVATE KEY-----
MIICXgIBAAKBgQDDEOX/tFJZrgR0dtTN2/jgPAJjWKE68aw8ayYaGn9fo1sJAE3C
uH6Ym3hu775Enfd5DhtJ38g8RCFLzGVP/LW6n4+LsKS5HRZTGcDkpME0sVoLHLZd
w8z4xZe5h+lT0jwkap5BNyHJCSddipxzjQIEtW+w8V6BkKkFw6UYN1Xn5QIDAQAB
AoGAUeS0Ssfvksrl/+crrElfkPRgpEi/V7nCb5Mkae0Z8JLqUzsXalp+e585zolE
PhZ7oQz1E+ypafPIbsQe/JfByx3itUk7J8+bZO4TpE8n5Afz8EdZLIqJU11MoafH
mWYYWsoMdymgxasuu0ygyeswP42/aw1M+qQgoWBSoPtgLrkCQQDsygWQRI868JKJ
OXzeKV6HTKjGXg37Zm050UaPk2a8inGk6F5RqH1+IZ4istrlcJTpJTuQCsVHJ+SQ
nLveL09vAkEA0uRPeSdXbi92AR/5fj2Xh2APerYjRgK11nh4QEiqbmKyNdW7r9zb
tIQiL9f4AXvcwIVnSWVgiTCwWOa9w8lT6wJBAOMlWPjwC8YqiSeCMjqbzMZVz4Gb
MCZ+N0FDdEC+0csDs8jR78i9rMSWUzBOCpYWzYJp6R1gd6auqh/feojFMZkCQQCO
Gkly2Y+QL2rUVzdGWTpBffjwNsqN4kWkvohIyK4Os3Jh1CMj3S4t9NsUYfI7Dbsx
/rIaQrVJvAUX4mL8Ci0BAkEAuAZBSTmd7MQybVlWCP1AVvlMyW1CV/Mts4tLsGO5
NRMuXY0CrQaO69MW4nuHCSmshBcNB7ahGxYYYMaHmem3QQ
-----END RSA PRIVATE KEY-----

When I try with the same key without the encapsullation headers ( -----BEGIN RSA PRIVATE KEY----- and -----END RSA PRIVATE KEY----- ) it is failing. 当我尝试使用没有封装头的相同密钥( -----BEGIN RSA PRIVATE KEY----------END RSA PRIVATE KEY----- )时,它失败了。

Does these headers are mandatory for the keys? 这些标头是否是密钥必需的?

If I want to use the key without headers which API of OpenSSL should i use? 如果我想使用不带标题的密钥,应该使用哪个OpenSSL API?

The type of the key format is defined by the header and footer of the PEM encoded key. 密钥格式的类型由PEM编码密钥的页眉和页脚定义。 Internally it is just a PKCS#1 private key. 在内部,它只是PKCS#1私钥。 For more information about the format you can look at this Q/A or the ASN.1 decoded key here . 有关格式的更多信息,请参见此处的 Q / A或ASN.1解码密钥。

So although all the information is in the base 64 encoding in the middle implementations may not directly be able to parse it, mainly because the type of the structure is not known. 因此,尽管在中间实现中所有信息都是以base 64编码的,但可能无法直接解析它,主要是因为结构的类型未知。

You can however base 64 decode it and use it as a key within OpenSSL. 但是,您可以使用base 64对其进行解码,并将其用作OpenSSL中的密钥。 You may need to specify -inform DER or something similar in that case. 在这种情况下,您可能需要指定-inform DER或类似的内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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