bouncycastle连接到Android Studio [英] bouncycastle connect to android studio

查看:95
本文介绍了bouncycastle连接到Android Studio的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Good time of day, I need to somehow connect the bouncycastle library to android studio. How can this be done? I've never dealt with one before. Here is the code for which I need this library:

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);

预先感谢您的帮助)

推荐答案

在模块(应用程序级)Gradle文件(通常为 app / build.gradle )中添加此依赖项

In your module (app-level) Gradle file (usually app/build.gradle) add this dependency

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

这篇关于bouncycastle连接到Android Studio的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆