简体   繁体   English

Windows,OpenSSL从key.pem和cert.pem生成一个新的.pem

[英]Windows, OpenSSL generate a new .pem from key.pem and cert.pem

I have the following files Cert.pem, Key.pem, CACert.pem 我有以下文件Cert.pem,Key.pem,CACert.pem

I have been told that I need to decrypt the key.pem. 有人告诉我,我需要解密key.pem。 1) What is the windows OpenSSL command to do this? 1)什么是Windows OpenSSL命令来做到这一点?

I need to combine the decrypted key.pem file with the cert.pem file to produce a new cert.pem file. 我需要将解密的key.pem文件与cert.pem文件结合起来以产生一个新的cert.pem文件。 2) What is the windows OpenSSL command to do this? 2)Windows OpenSSL命令执行此操作是什么?

Thanks 谢谢

Unix installations of OpenSSL should include man pages, but Windows versions often do not because Windows doesn't usually have any way of finding and displaying them. Unix安装的OpenSSL应该包括手册页,但Windows版本通常不包含手册页,因为Windows通常没有任何找到和显示它们的方法。 man pages for the currently supported releases, plus 'master' which is the development head, are available on the OpenSSL website at https://www.openssl.org/docs/manpages.html . 当前受支持的发行版的手册页以及开发头“ master”可在OpenSSL网站上找到,网址为https://www.openssl.org/docs/manpages.html All OpenSSL 'commands' are actually run by the (single) program openssl , thus you execute pkey some args by running 所有OpenSSL'commands'实际上都由(单个)程序openssl ,因此您可以通过运行pkey some args执行pkey some args

 openssl pkey some args
 rem if openssl.exe is on your PATH or in the current directory, otherwise
 x:\path\to\openssl pkey some args

You don't mention having the password for the encrypted key file; 您没有提到拥有加密密钥文件的密码; I hope you do because you can't decrypt (or do anything else) without it. 我希望您能这样做,因为没有它您将无法解密(或执行其他任何操作)。

For 1.0.0 up, pkey is the preferred way to convert private keys, including encrypting and decrypting; 对于1.0.0或更高版本, pkey是转换私钥(包括加密和解密)的首选方法。 see its man page. 参见其手册页。 In brief you simply tell pkey to read from the input file and write to the output file, and omit any specification of a cipher; 简而言之,您只需告诉pkey从输入文件读取并写入输出文件,并省略任何密码规范即可; that omission will cause it to write an unencrypted key. 遗漏将导致它写入未加密的密钥。 Note pkey will write the output in PKCS8 format, which is preferred for most purposes, but if you actually need a 'legacy' or 'traditional' format for some reason -- ask whoever 'told' you what software this file will be used with -- 1.1.0 pkey can do this but earlier cannot. 注意pkey会写在PKCS8格式,这是首选大多数用途的输出,但如果你真的需要一个“传统”或“传统”格式出于某种原因-谁问“告诉”你什么软件这个文件将被使用-1.1.0 pkey可以做到这一点,但是更早的时候不能。 If you are stuck with a 0.9.x release, usually only on obsolete systems, use pkcs8 -topk8 -nocrypt for PCKS8 output; 如果您坚持使用0.9.x版本(通常仅在过时的系统上), pkcs8 -topk8 -nocrypt对PCKS8输出使用pkcs8 -topk8 -nocrypt see that. 看到那个。

If you need legacy/traditional format (on a release below 1.1.0) you must use the 'legacy' per-algorithm commands, so you need to know what algorithm your key(file) is . 如果您需要旧式/传统格式(在1.1.0以下的发行版中),则必须使用“旧式”每个算法命令,因此您需要知道key(file) 什么算法。 Look at the first line where it says -----BEGIN something PRIVATE KEY----- . 看第一行,它显示-----BEGIN something PRIVATE KEY----- If something is RSA, use rsa ; 如果是RSA,请使用rsa for DSA dsa ; 用于DSA dsa ; for EC ec ; 对于EC ec ; see the respective pages. 请参阅相应页面。 If something is ENCRYPTED you must decrypt it to PkCS8 as above first, then look at it with asn1parse to determine which algorithm it is, but I expect it's not very likely someone who want a legacy unencrypted key will start with an PKCS8 encrypted one. 如果事情是ENCRYPTED您必须将其解密,以PKCS8于文首,再看看它asn1parse以确定它是哪种算法,但我希望这不是谁想要一个旧的未加密的密钥将与PKCS8加密的一个开始很可能有人。

OpenSSL does not provide any special operation to combine PEM files, since concatenating files of many types is a common operation. OpenSSL没有提供任何特殊的操作来组合PEM文件,因为连接许多类型的文件是一种常见的操作。 On Unix this is canonically done with the cat program; 在Unix上,这通常通过cat程序完成。 on Windows it can be done by using the (builtin) copy command with plus-sign(s) in the source; 在Windows上,可以使用(内置) copy命令在源代码中加上加号来完成; on both Unix and Windows it can be done by creating a file and then appending to it like: 在Unix和Windows上,都可以通过创建一个文件,然后将其追加为一个文件来完成:

 copy decryptedkey.pem combined.pem
 type certificate.pem >> combined.pem
 rem >> means redirect the output from that command ('type') 
 rem normally on the console to _the end of_ the named file.

In this case you want to modify cert.pem by adding the contents of decryptedkey.pem, so just do 在这种情况下,您想通过添加解密密钥.pem的内容来修改cert.pem,因此只需执行

 type decryptedkey.pem >> cert.pem

Alternatively you can use a plaintext editor like notepad. 另外,您可以使用记事本之类的纯文本编辑器。 Open both files; 打开两个文件; select all the text in the second file and copy (or cut) and paste it at the end of the first file; 选择第二个文件中的所有文本,然后复制(或剪切)并将其粘贴到第一个文件的末尾; save the modified first file. 保存修改后的第一个文件。

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

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