开发者

Import keystore in my app

开发者 https://www.devze.com 2023-04-11 20:45 出处:网络
I successfully created the myKeystore.bks file which i saved to the located \"C:\\test\\myKeystore.bks\".

I successfully created the myKeystore.bks file which i saved to the located "C:\test\myKeystore.bks". How do i import this keystore now in my app to get the handshake done?

InputStream in = context.getResources().openRawResource(R.raw.mykeystore);

I have following code from Antoine`s Blog which states "Now you can copy the keystore as a raw resource in your android app under res/raw/"

private SSLSocketFactory newSslSocketFactory() {   
  try {   
    // Get an instance of the Bouncy Castle KeyStore format  
       KeyStore trusted = KeyStore.getInstance("BKS");  
    // Get the raw resource, which contains the keystore with           
    // your trusted certificates (root and any intermediate certs)   
       Inpu开发者_如何学编程tStream in = context.getResources().openRawResource(R.raw.mykeystore);      
       try {  

Thank you in advance.


Old question. This answer is relevant to now.

Assuming you're using Android Studio.

To place a file in a specific resource folder In the project explorer,

  1. Open your project folder.
  2. Locate the res folder and expand the twistie to reveal the different resource folders.

    • If you don't have one there called, "Raw", then:
    • with the "Res" folder selected in the project explorer,
    • go to the File pulldown menu and select, New > Android Resource Directory.
      • A form will open, "New Resource Directory". Fill in the following.
      • Directory Name: raw
      • Resource Type: raw
      • Source set: main
  3. Now that you have a "Raw" folder, right click on it and choose to open the location on the file system (on the mac, it's "Reveal in Finder")

  4. Once the folder is opened, drop your keystore in there. Android studio should automatically show it in the Project Explorer inside the Raw folder.

Hope this helps.

Note: I'm using OSX hence the flows may differ, but you get the general idea.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号