Java 使用keytool生成私钥和公钥文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/32867898/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Generate private and public key file using keytool
提问by user3185729
I want to know if there is a way to create .key file for (public and private key) using keytool , I understand that we can generate a keystore using below command
我想知道是否有办法使用 keytool 为(公钥和私钥)创建 .key 文件,我知道我们可以使用以下命令生成密钥库
keytool -genkeypair -keysize 2048 -keyalg RSA -alias appalias -keystore D:\..\..
keytool -genkeypair -keysize 2048 -keyalg RSA -alias appalias -keystore D:\..\..
which has the keypair , I am also aware of java way of retrieving the keys from keystore , but is there a direct way for it using KEYTOOL
它有密钥对,我也知道从密钥库中检索密钥的 java 方法,但是是否有使用 KEYTOOL 的直接方法
回答by skywalker
As far as I remember puttygen can generate public and private key files. Try it and let me know if it works. Regards
据我所知 puttygen 可以生成公钥和私钥文件。试试看,让我知道它是否有效。问候
http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html
http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html
回答by user3185729
As per the findings there is no direct way to extract the private key out of the keystore , this link How can I export my private key from a Java Keytool keystore?helped to me extract the keys , it requires OpenSSL but i think thats the only way to go.
根据调查结果,没有直接的方法可以从密钥库中提取私钥,此链接如何从 Java Keytool 密钥库导出我的私钥?帮助我提取密钥,它需要 OpenSSL,但我认为这是唯一的方法。
回答by Krishnaraj
It's possible to extract the public keys using keytool, check this link.
可以使用 keytool 提取公钥,请查看此链接。
Export/import commands We'll use the keytool -exportcommand to extract the public key into a file, and then use the keytool -importcommand to insert it into a new keystore. Here's the command to extract the client's public key:
keytool -export -alias clientprivate -keystore client.private -file temp.key -storepass clientpw
And here's the command to insert the client's private key into its own keystore:
keytool -import -noprompt -alias clientpublic -keystore client.public -file temp.key -storepass public
We'll also extract and store the server's public key. Here's the command to extract the key:
keytool -export -alias serverprivate -keystore server.private -file temp.key -storepass serverpw
And here's the command to place it in its own keystore:
keytool -import -noprompt -alias serverpublic -keystore server.public -file temp.key -storepass public
导出/导入命令 我们将使用keytool -export命令将公钥提取到文件中,然后使用keytool -import命令将其插入到新的密钥库中。这是提取客户端公钥的命令:
keytool -export -alias clientprivate -keystore client.private -file temp.key -storepass clientpw
这是将客户端的私钥插入其自己的密钥库的命令:
keytool -import -noprompt -alias clientpublic -keystore client.public -file temp.key -storepass public
我们还将提取并存储服务器的公钥。这是提取密钥的命令:
keytool -export -alias serverprivate -keystore server.private -file temp.key -storepass serverpw
这是将它放在自己的密钥库中的命令:
keytool -import -noprompt -alias serverpublic -keystore server.public -file temp.key -storepass public