【问题标题】:bouncycastle connect to android studiobouncycastle 连接到安卓工作室
【发布时间】:2019-03-16 02:37:46
【问题描述】:

一天中的美好时光,我需要以某种方式将 bouncycastle 库连接到 android studio。如何才能做到这一点?我以前从未处理过一个。 这是我需要这个库的代码:

Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());
        byte[] input = "www.javaCODEgeeks.com".getBytes();
        byte[] keyBytes = new byte[]{0x01, 0x23, 0x45, 0x67, (byte) 0x89, (byte) 0xab, (byte) 0xcd,


                (byte) 0xef};



        byte[] ivBytes = new byte[]{0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00};


        SecretKeySpec pKey = new SecretKeySpec(keyBytes, "DES");

        IvParameterSpec ivectorSpecv = new IvParameterSpec(ivBytes);

        Cipher c = Cipher.getInstance("DES/CBC/PKCS7Padding", "BC");


        System.out.println("input : " + new String(input));


        // encryption pass


        c.init(Cipher.ENCRYPT_MODE, pKey, ivectorSpecv);


        byte[] encr = new byte;


        int ctLen = c.update(input, 0, input.length, encr, 0);


        ctLen += c.doFinal(encr, ctLen);


        System.out.println("cipher: " + new String(encr).getBytes("UTF-8").toString() + " bytes: " + ctLen);
        c.init(Cipher.DECRYPT_MODE, pKey, ivectorSpecv);
        byte[] decrpt = new byte;
        int ptLen = c.update(encr, 0, ctLen, decrpt, 0);
        ptLen += c.doFinal(decrpt, ptLen);
        System.out.println("plain : " + new String(decrpt) + " bytes: " + ptLen);

提前感谢您的帮助)

【问题讨论】:

  • 您无法将附加库添加到 android studio XD ;) 您可以将其添加到您的应用中。

标签: android bouncycastle


【解决方案1】:

在你的模块(应用级)Gradle 文件(通常是app/build.gradle)中添加这个依赖

implementation 'org.bouncycastle:bcpkix-jdk15on:1.56'

【讨论】:

  • 您好。您将如何使用此实现? AKA - 您如何将其导入脚本以供使用? import org.bouncycastle:bcpkix-jdk15on:1.56 给出错误:“期待顶级声明”
  • 我也尝试不使用导入并在此行中的 org 和 bouncycastle 之后得到“期望元素”:Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());跨度>
猜你喜欢
  • 2013-07-08
  • 2017-04-17
  • 2014-04-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多