gpt4 book ai didi

Java 中的 java.security.UnrecoverableKeyException : Get Key failed: null while reading . p12 文件

转载 作者:搜寻专家 更新时间:2023-11-01 03:24:06 24 4
gpt4 key购买 nike

我正在尝试从从 Google 服务帐户控制台下载的 .p12 文件中提取私钥。

我正在从文件夹位置读取此 .p12 并创建 KeyStore 对象。

KeyStore myStore = null;
FileInputStream in_cert = new FileInputStream(
"D://Google Analytics//login//GA//6aa55af54232dfa60b60a908ff0138bba1147d63-privatekey.p12");

myStore = KeyStore.getInstance("PKCS12");
myStore.load(in_cert, null); // if i give "changeit" as the password(hopefully the default keystore password) gets the exception "java.security.UnrecoverableKeyException: Get Key failed: Given final block not properly padded. If null is passed as an argument the program runs fine with output as "privatekey""

Enumeration<String> aliases = myStore.aliases();
String alias = "";
System.out.println(myStore.aliases());

while (aliases.hasMoreElements()) {
System.out.println(aliases.nextElement()); // prints privatekey
}

java.security.PrivateKey privateKey = (PrivateKey) myStore.getKey("privatekey", null); // gives exception "java.security.UnrecoverableKeyException: Get Key failed: null"

我做错了什么?

我需要私钥作为签名者来创建 Google JSON Web Token。

最佳答案

以防万一有人降落在这里,如 @prathamesh_mb 所述,您需要在加载 key 时提供密码。

PrivateKey privateKey = (PrivateKey) myStore.getKey("privatekey", "yourpasswordhere".toCharArray());

关于Java 中的 java.security.UnrecoverableKeyException : Get Key failed: null while reading . p12 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19976084/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com