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

你可能感兴趣的:(Bouncy Castle 配置.)