Convert JKS to BKS using keytool

English 简体中文 繁体中文 ภาษาไทย Tiếng Việt
Summary

Converting a JKS keystore to the BouncyCastle BKS format with Java's keytool requires specific steps due to BKS not being a native Java SE keystore type. Developers must first download the BouncyCastle provider JAR. The keytool command then needs to include the -provider option, specifying org.bouncycastle.jce.provider.BouncyCastleProvider, and the -providerpath option, pointing to the downloaded BouncyCastle JAR file. This ensures the JVM can locate and utilize the third-party provider for the conversion process. This approach is generally applicable for converting between various keystore formats using external providers.

有很多問題(問題 1問題 2)在Stack Overflow上討論如何使用Java keytool將JKS金鑰庫轉換為 BKS金鑰庫(BouncyCastle提供的金鑰庫格式)。

這個轉換問題之所以很多,是因為BKS不是Java SE支援的金鑰庫格式,它是一個第三方金鑰庫格式。要將JSK轉換為BKS,必須先下載BKS提供者。並且在執行keytool命令時需要新增一些選項。

將JKS金鑰庫轉換為BKS金鑰庫的典型命令如下所示:

keytool -importkeystore -srckeystore testkeys -srcstoretype JKS -srcstorepass passphrase -destkeystore testkeys.bks -deststoretype BKS -deststorepass password -provider org.bouncycastle.jce.provider.BouncyCastleProvider -providerpath [PARENT_DIRECTORY_PATH]\bouncycastle\bcprov-jdk15on-152.jar

兩個重要的選項是-provider-providerpath。 -provider選項告訴JVM BKS金鑰庫服務註冊在哪裡,-providerpath選項告訴JVM提供者可以在哪裡找到。

這樣,將JKS金鑰庫轉換為BKS金鑰庫應該沒有問題。下面顯示一個例子。

轉換前,JKS金鑰庫包含以下條目:

轉換後,BKS金鑰庫包含以下條目:

如果您想在不同的金鑰庫格式之間進行轉換,命令應該類似。

JAVA SECURITY JKS KEYTOOL BKS

  RELATED

  COMMENTS

3
Anonymous
Jun 2, 2017 at 6:37 am

Problem importing entry for alias capistore: java.security.KeyStoreException: java.io.IOException: Error initialising store of key store: java.security.InvalidKeyException: Illegal key size.

 

I keep getting the above error, any help would be appriciated 

Ke Pi
Jun 3, 2017 at 4:00 am

It may relate to the limited policy strength files located in jre\lib\security. Can you try to put the unlimited strength policy files there?

Anonymous
Feb 4, 2024 at 5:10 am

There are any ways to convert it using java methods? For example add dependency "implementation 'org.bouncycastle:bcprov-jdk18on:1.77'" and use it for transformation?