0
我正在嘗試在Java(JDK 1.7)中開發一個模塊,將數字簽名應用於帶有PKCS#7密碼信封的數字文檔。如何在Java中生成加密簽名PKCS#7?
我使用java類KeyStore
(java.security.KeyStore
),我擁有一個文件keystore.ks
,並且我有憑據(密碼)。
我試圖打印在裏面的證書,用下面的代碼的第一件事:
public static void main(String[] args) throws Exception {
String keystoreFilename = PATH_TO_KEYSTORE;
char[] password = KEYSTORE_PASSWORD.toCharArray();
FileInputStream fIn = new FileInputStream(keystoreFilename);
KeyStore keystore = KeyStore.getInstance(KEYSTORETYPE);
Provider temp = keystore.getProvider();
System.out.println(temp.getName());
KeyStore keystore = KeyStore.getInstance(KEYSTORETYPE);
FileInputStream input = new FileInputStream(PATH_TO_KEYSTORE);
try {
keystore.load(input, KEYSTORE_PASSWORD.toCharArray());
} catch (IOException e) {
System.out.println("ERROR:"+e.getMessage());
} finally {
if (input != null) {
input.close();
}
}
Certificate cert = keystore.getCertificate(KEY_ALIAS_IN_KEYSTORE);
System.out.println(cert);
}
此代碼返回如下:
error: "Invalid keystore format" (KEYSTORETYPE = "JKS")
當我試圖攜帶的負載其中包含的證書。
誰能告訴我什麼是錯?