android底层rsa加密,android 下RSA加密解密
参考文章
Base64.java需要换成下面这个类
package club.hb168.hmi.util.rsa;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
public class Base64 {
private static final char[] legalChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
.toCharArray();
public static String encode(byte[] data) {
int start = 0;
int len = data.length;
StringBuffer buf = new StringBuffer(data.length * 3 / 2);
int end = len - 3;
int i = start;
int n = 0;
while (i <= end) {
int d = ((((int) data[i]) & 0x0ff) << 16)
| ((((int) data[i + 1]) & 0x0ff) << 8)
| (((int) data[i + 2]) & 0x0ff);
buf.append(legalChars[(d >> 18) & 63]);
buf.append(legalChars[(d >> 12) & 63]);
buf.append(legalChars[(d >> 6) & 63]);
buf.append(legalChars[d & 63]);
i += 3;
if (n++ >= 14) {
n = 0;
buf.append(" ");
}
}
if (i == start + len - 2) {
int d = ((((int) data[i]) & 0x0ff) << 16)
| ((((int) data[i + 1]) & 255) << 8);
buf.append(legalChars[(d >> 18) & 63]);
buf.append(legalChars[(d >> 12) & 63]);
buf.append(legalChars[(d >> 6) & 63]);
buf.append("=");
} else if (i == start + len - 1) {
int d = (((int) data[i]) & 0x0ff) << 16;
buf.append(legalChars[(d >> 18) & 63]);
buf.append(legalChars[(d >> 12) & 63]);
buf.append("==");
}
return buf.toString();
}
private static int decode(char c) {
if (c >= 'A' && c <= 'Z')
return ((int) c) - 65;
else if (c >= 'a' && c <= 'z')
return ((int) c) - 97 + 26;
else if (c >= '0' && c <= '9')
return ((int) c) - 48 + 26 + 26;
else
switch (c) {
case '+':
return 62;
case '/':
return 63;
case '=':
return 0;
default:
throw new RuntimeException("unexpected code: " + c);
}
}
/**
* Decodes the given Base64 encoded String to a new byte array. The byte
* array holding the decoded data is returned.
*/
public static byte[] decode(String s) {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
try {
decode(s, bos);
} catch (IOException e) {
throw new RuntimeException();
}
byte[] decodedBytes = bos.toByteArray();
try {
bos.close();
bos = null;
} catch (IOException ex) {
System.err.println("Error while decoding BASE64: " + ex.toString());
}
return decodedBytes;
}
private static void decode(String s, OutputStream os) throws IOException {
int i = 0;
int len = s.length();
while (true) {
while (i < len && s.charAt(i) <= ' ')
i++;
if (i == len)
break;
int tri = (decode(s.charAt(i)) << 18)
+ (decode(s.charAt(i + 1)) << 12)
+ (decode(s.charAt(i + 2)) << 6)
+ (decode(s.charAt(i + 3)));
os.write((tri >> 16) & 255);
if (s.charAt(i + 2) == '=')
break;
os.write((tri >> 8) & 255);
if (s.charAt(i + 3) == '=')
break;
os.write(tri & 255);
i += 4;
}
}
}
~~~~~~~~~~~~~~~~~~~~~~~~
造成这样的原因主要是因为安卓RSA的加密标准跟服务端加密标准不一样
安卓端加密标准为:RSA/ECB/PKCS1Padding
服务端加密标准为:RSA
在Android中应该使用这个标准
Cipher cipher = Cipher.getInstance("RSA/ECB/PKCS1Padding");
在服务端使用这个标准
Cipher cipher = Cipher.getInstance("RSA");
转载于:https://www.cnblogs.com/pigy/p/6700095.html
android底层rsa加密,android 下RSA加密解密相关推荐
- 怎么看android底层源码,Android 底层按键获取
与用户交互的输入设备(触摸屏,键盘等)是获取用户意图的来源.由于硬件本身的物理特性及由各大硬件厂商的标准不一,这将导致我们从设备上获取到的键值存在一定的差异性,为了让系统能够正确处理用户的操作,我们就 ...
- linux luks分区加密,Linux下分区加密LUKS
Linux内核自带的磁盘分区加密,与Android的dm-crypt同样方便. 编程随想曾经介绍过LUKS和VeraCrypt,博主把两者都测试了一下,写下LUKS的使用方法. 创建 假设要在/dev ...
- Android底层隐私数据,Android Intent传递数据底层分析详细介绍_Android_脚本之家
Android Intent传递数据底层分析详细介绍 我们知道在Activity切换时,如果需要向下一个ActivityB传递数据,可以借助Intent对象的putExtra方法. 但是不知各位有没 ...
- 怎么看android底层源码,Android底层有必定的认识,研究过相关的Android源码
1.系统架构:java 一).系统分层:(由下向上)[如图]android 一.安卓系统分为四层,分别是Linux内核层.Libraries层.FrameWork层,以及Applications层:g ...
- android底层开发工具,Android Developer Tools(开发人员工具)
在做Android开发的过程中,不可避免地需要使用到自带的android developer tools(开发人员工具),这是一个强大的开发辅助工具,随着android版本的更新,developer ...
- linux解除硬盘加密,linux下硬盘加密
由于RHEL5.3已经在GUI的安装中默认支持 LUKS了,我这才真正的开始尝试使用LUKS,因为之前开源界对于磁盘加密的方案有若干中,始终没法统一,所以一直没有决定去学用哪一种.其实5.2已经支持L ...
- fiyme android底层,魅族首批Android 10底层Flyme于今日正式推送
原标题:魅族首批 Android 10 内测版今日起开始推送 7月21日消息 魅族官方曾于 6 月 25 日宣布为旗下 10 款机型的 Flyme 适配 Android 10 系统底层.从 6 月 2 ...
- android 底层系统开发,Android底层
概述-Android系统架构 Android系统架构 概述-Application Application Android平台不仅仅是操作系统,同时也包含了许多应用,如桌面,浏览器,视频客户端,摄像头 ...
- android底层音频调试,Android音频底层调试-基于tinyalsa,使用中碰到问题
参考http://blog.csdn.net/zgyrelax/article/details/39397553 已编译出tinyalsa.so, tinymix tinyplay, tinycap ...
最新文章
- 最佳页面置换算法代码_(存储管理)页面置换算法
- MoSonic:对SubSonic的分布式存储、缓存改进尝试(2)
- css浮动+应用(瀑布流效果的实现)
- JZOJ 5234. 【NOIP2017模拟8.7A组】外星人的路径
- 解决Linux新创建的文件夹带锁问题
- ORM框架 之 Entity Framework
- C/C++基础::sizeof() 与 sizeof(string)
- MongoDB数据库和集合的基本操作
- 机器学习算法总结(六)——EM算法与高斯混合模型
- 敏捷开发中XP与SCRUM的区别
- mysql 什么是审核上线_自动审核及上线系统
- 2018年最新税收分类编码_这是我们在2018年推出的所有免费编码课程
- 关于echarts3总chinamap的配置问题
- Web前端:7大Web开发趋势和技术
- 计算机考试界面没有验证码,win10系统下网页验证码显示不了的两种解决方法
- 雷军做程序员时写的博客,真心强啊。。
- 多项式计算的Horner 方法
- 好用的 APISpace 车牌识别API
- 关于网络下载的记忆碎片
- mini2440 sd卡支持