二进制和byte数组的互相转换,zip的加密
/**
* byte数组转换为二进制字符串,每个字节以","隔开
**/
public static String conver2HexStr(byte[] b) {
StringBuffer result = new StringBuffer();
for (int i = 0;
i < b.length;
i++) {
result.append(Long.toString(b[i] & 0xff, 2) + ",");
}
return result.toString().substring(0, result.length() - 1);
}/**
* 二进制字符串转换为byte数组,每个字节以","隔开
**/
public static byte[] conver2HexToByte(String hex2Str) {
String[] temp = hex2Str.split(",");
byte[] b = new byte[temp.length];
for (int i = 0;
i < b.length;
i++) {
b[i] = Long.valueOf(temp[i], 2).byteValue();
}
return b;
}/**
* byte数组转换为十六进制的字符串
**/
public static String conver16HexStr(byte[] b) {
StringBuffer result = new StringBuffer();
for (int i = 0;
i < b.length;
i++) {
if ((b[i] & 0xff) < 0x10)
result.append("0");
result.append(Long.toString(b[i] & 0xff, 16));
}
return result.toString().toUpperCase();
}/**
* 十六进制的字符串转换为byte数组
**/
public static byte[] conver16HexToByte(String hex16Str) {
char[] c = hex16Str.toCharArray();
byte[] b = new byte[c.length / 2];
for (int i = 0;
i < b.length;
i++) {
int pos = i * 2;
b[i] = (byte) ("0123456789ABCDEF".indexOf(c[pos]) << 4 | "0123456789ABCDEF".indexOf(c[pos + 1]));
}
return b;
}
【二进制和byte数组的互相转换,zip的加密】}
推荐阅读
- 急于表达——往往欲速则不达
- 第三节|第三节 快乐和幸福(12)
- 20170612时间和注意力开销记录
- 2.6|2.6 Photoshop操作步骤的撤消和重做 [Ps教程]
- 对称加密和非对称加密的区别
- 眼光要放高远
- 樱花雨
- 前任
- 2020-04-07vue中Axios的封装和API接口的管理
- 烦恼和幸福