android - bouncycastle 连接到安卓工作室
问题描述
一天中的美好时光,我需要以某种方式将 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);
在此先感谢您的帮助)
解决方案
在您的模块(应用程序级)Gradle 文件中(通常app/build.gradle
)添加此依赖项
implementation 'org.bouncycastle:bcpkix-jdk15on:1.56'
推荐阅读
- r - 排除列中值的过滤函数
- ubuntu - boost 不包含 /lib 目录吗?
- javascript - React中无效的挂钩调用,但它适用于其他人
- react-native - Expo app.config.js googleServicesFile 用于不同的构建变体
- java - 我如何在 Spring 中使用 @CachePut 进行收集?
- python - 单元测试时如何从数据库异步获取记录?
- vb.net - VB.NET:是否有替代使用按位逻辑运算符在记录中查找匹配项的方法?
- amazon-web-services - Amazon Textract 在进行分析时会跳过一些表单字段
- javascript - 返回长度为偶数的 firstName 值的数量
- django - 您应该直接在视图中访问cleaned_data,还是拥有一个属于给定表单的方法来处理cleaned_data?