资源简介
java对idea算法的实现,// String key = "0000000000000000";
// String data = "11111111冯";
// byte[] bytekey = key.getBytes();
// byte[] bytedata = data.getBytes();
//
// IDEA idea = new IDEA();
// byte[] encryptdata = idea.IdeaEncrypt(bytekey, bytedata, true);
// byte[] decryptdata = idea.IdeaEncrypt(bytekey, encryptdata, false);
//
// System.out.println("--------------------------------");
//
// for (int i = 0; i < bytedata.length; i++) {
// System.out.print(" " + bytedata[i] + " ");
// }
//
// System.out.println("");
//
// for (int i = 0; i < encryptdata.length; i++) {
// System.out.print(" " + encryptdata[i] + " ");
// }
//
// System.out.println("");
//
// for (int i = 0; i < decryptdata.length; i++) {
// System.out.print(" " + decryptdata[i] + " ");
代码片段和文件信息
public class IDEA {
private byte[] bytekey;
public byte[] getKey(String key){
int len1 =key.length();
if (len1>=16) {
key=key.substring(0 16);
} else {
for (int i=0;i<16-len1;i++){
key=key.concat(“0“);
}
}
bytekey=key.getBytes();
return bytekey;
}
/**
* 加密String明文输入String密文输出
* @param strMing
* @return
*/
public String getEncString(String strMing) {
byte[] byteMi = null;
byte[] byteMing = null;
String strMi = ““;
try {
return byte2hex(IdeaEncrypt(bytekeystrMing.getBytes()true) );
}
catch(Exception e){
e.printStackTrace();
}
finally {
byteMing = null;
byteMi = null;
}
return strMi;
}
/**
* 解密 以String密文输入String明文输出
* @param strMi
* @return
*/
public String getDesString(String strMi) {
byte[] byteMing = null;
byte[] byteMi = null;
String strMing = ““;
try {
String tmp= new String(IdeaEncrypt(bytekeyhex2byte(strMi.getBytes())false ));
int len1=tmp.length();
return tmp.substring(0 len1-6);
}
catch(Exception e) {
e.printStackTrace();
}
finally {
byteMing = null;
byteMi = null;
}
return strMing;
}
private byte[] Encrypt(byte[] bytekey byte[] inputBytes boolean flag) {
byte[] encryptCode = new byte[8];
// 分解子密钥
int[] key = get_subkey(flag bytekey);
// 进行加密操作
encrypt(key inputBytes encryptCode);
// 返回加密数据
return encryptCode;
}
private int bytesToInt(byte[] inBytes int startPos) {
return ((inBytes[startPos] << 8) & 0xff00) +
(inBytes[startPos + 1] & 0xff);
}
private void intToBytes(int inputInt byte[] outBytes int startPos) {
outBytes[startPos] = (byte) (inputInt >>> 8);
outBytes[startPos + 1] = (byte) inputInt;
}
private int x_multiply_y(int x int y) {
if (x == 0) {
x = 0x10001 - y;
} else if (y == 0) {
x = 0x10001 - x;
} else {
int tmp = x * y;
y = tmp & 0xffff;
x = tmp >>> 16;
x = (y - x) + ((y < x) ? 1 : 0);
}
return x & 0xffff;
}
private void encrypt(int[] key byte[] inbytes byte[] outbytes) {
int k = 0;
int a = bytesToInt(inbytes 0);
int b = bytesToInt(inbytes 2);
int c = bytesToInt(inbytes 4);
int d = bytesToInt(inbytes 6);
for (int i = 0; i < 8; i++) {
a = x_multiply_y(a key[k++]);
b += key[k++];
b &= 0xffff;
c += key[k++];
c &= 0xffff;
d = x_multiply_y(d key[k++]);
int tmp1 = b;
int tmp2 = c;
c ^= a;
b ^= d;
c = x_multiply_y(c key[k++]);
b += c;
b &= 0xffff;
b = x_multiply_y(b key[k++]);
c += b;
c &= 0xffff;
a ^= b;
d ^= c;
b ^= tmp2;
c ^= tmp1;
}
intToBytes(x_multiply_y(a key[k++]) outbytes 0);
intToBytes(c + key[k++] outbytes 2);
intToBytes(b + key[k++] outbytes 4);
intToBytes(x_multiply_y(d key[k]) outbytes 6);
}
private int[] encrypt_subkey(byte[] byteKey) {
int[] key = new int[52];
if (byteKey.length < 16) {
byte[] tmpkey = new byte[16];
System.arraycopy(byteKey 0 tmpkey
tmpkey.length - byteKey.length byteKey.length);
byteKey = tmpkey;
}
for (int i = 0; i < 8; i++) {
key[i] = bytesToInt(byteKey i * 2);
}
f
相关资源
- mybatis_plus-17版本.zip
- mybatis_log_plugin_2020idea.jar
- java调用海康sdk案例
- 解决IDEA不支持带BOM的UTF-8编码文件,
- Java web 购物车Idea工程ServletCartDemo
- java+selenium+maven+testng自动化测试框架实
- Thinking in Java 4 源码 导入IDEA可直接运
- 图书管理系统 --- javaweb源码
- 使用IntelliJ IDEA开发基于Maven+Spring MV
- 基于JavaWeb的作业管理系统
- 尚硅谷_宋红康_IntelliJIDEA的安装、配置
- idea 创建javaWeb项目
- java使用idea搭建ssm+maven框架项目,单
- IntelliJ IDEA 2017 汉化包
- javaweb商品后台管理系统
- Euclidea_4.17破解版
- 黑马2018 JAVA IDEA 版 教程两套
- 毕业设计ssm点餐系统源码比较规范I
- 基于SSM使用idea构建的旅游网站---毕业
- Intellij IDEA 2017 中文包
- IntelliJ IDEA 2017.3 汉化包,2017.3下可以
- smalidea-0.05.zip
- JSP + laypage分页完整案例
- phpStorm 2019汉化包 解决无法打开设置问
- IntelliJ IDEA: idea2017.3.5汉化包、中文语
- IntelliJ IDEA 汉化包-resources_cn.jar
- java购物商城demo源码
- resources_zh_CN_idea2019.jar
- 网上书店前台系统软件测试课程设计
- 传智黑马前讲师JAVA2018最新完整视频(
评论
共有 条评论