哪个openssl keypair gen命令会产生我可以在Java 17中阅读的无密码的私钥?
在这一天中,最好的一天燃烧了。 Google说,使用PKCS#8格式作为私钥,因此
$ openssl genpkey -out my.prv.key -algorithm RSA -pkeyopt rsa_keygen_bits:2048
# from https://www.feistyduck.com/library/openssl-cookbook/online/ch-openssl.html
我尝试使用Kotlin代码
val stringKey = Files.readString(Path.of("/Users/matthewadams/my.prv.key"))
val keyFactory = KeyFactory.getInstance("RSA")
val privateKeySpec = PKCS8EncodedKeySpec(stringKey.toByteArray())
val key = keyFactory.generatePrivate(privateKeySpec)
i wally effere werferal 获得了一个例外
Caused by: java.security.InvalidKeyException: invalid key format
at java.base/sun.security.pkcs.PKCS8Key.decode(PKCS8Key.java:103)
at java.base/sun.security.pkcs.PKCS8Key.<init>(PKCS8Key.java:95)
at java.base/sun.security.rsa.RSAPrivateCrtKeyImpl.<init>(RSAPrivateCrtKeyImpl.java:153)
at java.base/sun.security.rsa.RSAPrivateCrtKeyImpl.newKey(RSAPrivateCrtKeyImpl.java:90)
at java.base/sun.security.rsa.RSAKeyFactory.generatePrivate(RSAKeyFactory.java:352)
at java.base/sun.security.rsa.RSAKeyFactory.engineGeneratePrivate(RSAKeyFactory.java:249)
... 121 more
时, 我发布了命令(Alpine openssl 1.1.1o)。 - 使用openssl
(在MacOS w/libressl或Alpine w/openssl上使用openssl
)的无RSA专用密钥,可以使用运行Java 17的Vanilla Kotlin代码读取?
无论我尝试什么变化,都没有任何可起步。谷歌谷歌无济于事。我觉得我缺少一些简单的东西。甚至尝试剥离-----开始私有密钥-----
&amp; -----结束私钥------
- 似乎无效...
Burned better part of a day on this. Google says use PKCS#8 format for the private key, so I issued command (alpine openssl 1.1.1o)
$ openssl genpkey -out my.prv.key -algorithm RSA -pkeyopt rsa_keygen_bits:2048
# from https://www.feistyduck.com/library/openssl-cookbook/online/ch-openssl.html
When I try to read this with Kotlin code
val stringKey = Files.readString(Path.of("/Users/matthewadams/my.prv.key"))
val keyFactory = KeyFactory.getInstance("RSA")
val privateKeySpec = PKCS8EncodedKeySpec(stringKey.toByteArray())
val key = keyFactory.generatePrivate(privateKeySpec)
I always get an exception
Caused by: java.security.InvalidKeyException: invalid key format
at java.base/sun.security.pkcs.PKCS8Key.decode(PKCS8Key.java:103)
at java.base/sun.security.pkcs.PKCS8Key.<init>(PKCS8Key.java:95)
at java.base/sun.security.rsa.RSAPrivateCrtKeyImpl.<init>(RSAPrivateCrtKeyImpl.java:153)
at java.base/sun.security.rsa.RSAPrivateCrtKeyImpl.newKey(RSAPrivateCrtKeyImpl.java:90)
at java.base/sun.security.rsa.RSAKeyFactory.generatePrivate(RSAKeyFactory.java:352)
at java.base/sun.security.rsa.RSAKeyFactory.engineGeneratePrivate(RSAKeyFactory.java:249)
... 121 more
How do I generate a password-less RSA private key using openssl
(on macos w/LibreSSL or alpine w/openssl) that can be read using vanilla Kotlin code running Java 17?
No matter what variation on this I try, nothing works. Googled a ton to no avail. I feel like I'm missing something simple. Even tried stripping off -----BEGIN PRIVATE KEY-----
& -----END PRIVATE KEY-----
-- nothing seems to work...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论