我正在尝试从从Google服务帐户控制台下载的.p12文件中提取privateKey。
我正在从文件夹位置读取此.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令牌的签名者。
提前致谢。