Bouncy Castle 配置.

一 , 配置方法:

1、官方站點下載Bouncy Castle的JCE Provider包 bcprov-ext-jdk15-145.jar
  2、把jar文件復制到 $JAVA_HOME$\jre\lib\ext 目錄下面
  3、修改配置文件\jre\lib\security[java.security](http://baike.baidu.com/view/637098.htm)
  4, 末尾添加security.provider.7=org.bouncycastle.jce.provider.BouncyCastleProvider

二, 測試程序

    public void testBouncyCastle(){
        try {
            System.out.print("Attempting to get a Blowfish key...");
            KeyGenerator keyGenerator=KeyGenerator.getInstance("Blowfish");
            keyGenerator.init(128);
            SecretKey key=keyGenerator.generateKey();
            System.out.println("OK");

            System.out.println("Attempting to get a Cipher and encrypt...");
            Cipher cipher=Cipher.getInstance("Blowfish/ECB/PKCS5Padding");
            cipher.init(Cipher.ENCRYPT_MODE,key);

            byte[] cipherText=cipher.doFinal("123".getBytes());
            System.out.println("OK");

            System.out.println("Test completed successfully.");
        } catch (Exception e) {
            LogUtils.e(TAG,"測試Bouncy Castle 失敗.");
        }
    }

三, 在Android studio中使用之間將包拷貝到工程中, 然后

project structure --> app ---> Dependencies ---> File Denpendency

參考 : http://www.cnblogs.com/duwenlei/p/3910772.html

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容