资源简介
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
相关资源
- java-upload分片文件接收,分片文件合并
- IDEA迁移eclipse快捷键配置jar包及代码模
- JetbrainsPatchKeygen-1.2.1.jar
- genSets.jar
- IntelliJ IDEA: 中文语言包、汉化包、中
- 基于JSP+Servlet+JavaBean+Dao开发模式——
- IDEA汉化包.zip
- idea+springboot+mybatis+jsp+bootstrap实现从
- 2020年最新javaSE教程的,java零基础入门
- 2019年java完整视频 idea版本.txt
- intellij idea java 白色eclipse高仿主题
- IntelliJ IDEA: 中文语言包、汉化包、中
- 2018传智播客JavaEE(IDEA版)视频教程绝
- IDEA setting文件
- IDEA算法(java)
- reviewboard-plugin-for-idea
- intellij idea 中文语言包resources_zh_CN_I
- 正版smalidea-0.0.5.zip,在android studio中安
- flutter插件
- 期末大作业JAVAWEB+MYSQL学生公寓系统
- mybatis-log-plugin.jar--支持最新idea2020.2
- easyCode配置.zip
- 基于idea的逆向工程源码文件
- JSP+Serlvet+JavaBean+Maven+MySql 学生学籍信
- IntelliJ IDEA 2018版新增的自带暗色主题
- IDEA支持带BOM的UTF-8编码文件的解决方
- Intellij idea 的配置导入
- Echarts可视化工具的使用案例idea
- idea主题控
- keymap-shkstart.rar
评论
共有 条评论