10

I have a certificate with .cer extension. My application will connect to site with https. I'm trying to create BKS with this command

keytool -import -alias tomcat -file X://KeyStore/fidoserver.crt -keypass password - keystore X://KeyStore/keystore.bks -storetype BKS -storepass 222222 -providerClass org.bouncycastle.jce.provider.BouncyCastleProvider -providerpath X://KeyStore/bcprov-jdk16-146.jar

, but get FileNotFound X://KeyStore/keystore.bks exception How to get BKS if i have .cer?

onCreate
  • 775
  • 3
  • 12
  • 35

1 Answers1

20

Try using this on Terminal (I assume you've downloaded Bouncy Castle jar at http://bouncycastle.org/latest_releases.html):

keytool -importcert -v -trustcacerts -file "path_to_cert/interm_ca.cer" -alias IntermediateCA -keystore "path_to_your_app/res/raw/myKeystore.bks" -provider org.bouncycastle.jce.provider.BouncyCastleProvider -providerpath "path_to_bouncycastle/bcprov-jdk16-145.jar" -storetype BKS -storepass mysecret

it should create a BKS keystore on your app's /res/raw folder. Then, verify your keystore with the following command:

keytool -list -keystore "path_to_your_app/res/raw/myKeystore.bks" -provider org.bouncycastle.jce.provider.BouncyCastleProvider -providerpath "path_to_bouncycastle/bcprov-jdk16-145.jar" -storetype BKS -storepass mysecret

it should output something like this: RootCA, 22.10.2010, trustedCertEntry, Thumbprint (MD5): 24:77:D9:A8:91:D1:3B:FA:88:2D:C2:FF:F8:CD:33:93 IntermediateCA, 22.10.2010, trustedCertEntry, Thumbprint (MD5): 98:0F:C3:F8:39:F7:D8:05:07:02:0D:E3:14:5B:29:43

Source

Lucas Jota
  • 1,863
  • 4
  • 24
  • 43
  • Thanks its works for me I have used .cert file path to convert it into .bks – Ramesh Chand Jan 09 '17 at 05:21
  • Also there is SO answer, maybe to someone will be helpful https://stackoverflow.com/questions/46871893/keystore-the-system-cannot-find-the-path-specified/46873905#46873905 – Sirop4ik Oct 22 '17 at 12:21
  • i'm having the same issue in convertring .crt to .bks in android studio ..Please help me –  Dec 15 '17 at 11:57
  • classpath 'keytool -import -v -trustcacerts -alias 0 -file mosqca.crt -keystore res/raw/mystore.bks -storetype BKS -provider org.bouncycastle.jce.provider.BouncyCastleProvider -storepass mypassword' –  Dec 18 '17 at 04:29
  • I have attached .crt file in raw folder in android,unable to convert it to .bks file ,i have downloaded bouncycastle.jar file but still i can't sync the gradle. –  Dec 18 '17 at 04:33
  • The "source" link is broken. – Pranav Karnik Feb 20 '19 at 12:34