密钥工具错误:java.lang.Exception:密钥库文件存在,但为空

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18913296/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 12:17:18  来源:igfitidea点击:

keytool error: java.lang.Exception: Keystore file exists, but is empty

javasslkeystorekeytool

提问by Aniket Thakur

I am new to SSL.

我是 SSL 的新手。

I am trying to create keystore for SSL connection using keytool. First I tried the following command

我正在尝试使用 keytool 为 SSL 连接创建密钥库。首先我尝试了以下命令

[aniket@localhost bin]$ keytool -genkey -alias myKeyStore -keyalg RSA -keystore
/home/aniket/keystore

It asked me password and other details and finally gave me following error

它问了我密码和其他详细信息,最后给了我以下错误

keytool error: java.io.FileNotFoundException: /home/aniket/keystore 
(Is a directory)

So I created a file keystoreFile.txt inside keystore folder and executed

所以我在 keystore 文件夹中创建了一个文件 keystoreFile.txt 并执行

[aniket@localhost bin]$ keytool -genkey -alias myKeyStore -keyalg RSA -keystore
/home/aniket/keystore/keystoreFile.txt

and now(no prompt for password etc) I am getting

现在(没有提示输入密码等)我得到

keytool error: java.lang.Exception: Keystore file exists, but is empty:
/home/aniket/keystore/keystoreFile.tx

What should be the contents of the file. I though keytool will generate key pair (a public key and associated private

文件的内容应该是什么。我虽然 keytool 会生成密钥对(公钥和关联的私钥

采纳答案by Joe Elleson

Delete the empty keystoreFile.txt, then run your 2nd command again

删除空的 keystoreFile.txt,然后再次运行您的第二个命令

[aniket@localhost bin]$ keytool -genkey -alias myKeyStore -keyalg RSA -keystore
/home/aniket/keystore/keystoreFile.txt

It's trying to createthe file you specify with the -keystoreflag. The reason your first one command failed is that you gave it an existing directory name.

它正在尝试创建您使用-keystore标志指定的文件。你的第一个命令失败的原因是你给它一个现有的目录名。