/**
* 此方法根据异或方法实现加密与解密的过程
*/
package com.cainwise.util;
import java.io.UnsupportedEncodingException;
public class Cipher_duicheng {
//密钥
private final static String key = "uiow92384!@#5^&*(-==9@@(==)";
//将一个字符串与一个字节进行计算,生成一个新字符串.
private static String pass(byte b,String str){
byte[] ee;
try {
ee = str.getBytes("ISO-8859-1");
for(int i = 0 ;i<ee.length;i++){
ee[i] = (byte)(ee[i] ^ b);
}
return new String(ee,"ISO-8859-1");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
return "";
}
}
//加密方法
public static String compose(String code){
String tcode = code;
for(int i=0;i<key.length();i++){
byte b = (byte)key.charAt(i);
tcode = pass(b,tcode);
}
return tcode;
}
//解密码算法
public static String parse(String code){
String tcode = code;
for(int i=key.length();i > 0;i--){
byte b = (byte)key.charAt(i-1);
tcode = pass(b,tcode);
}
return tcode;
}
}
* 此方法根据异或方法实现加密与解密的过程
*/
package com.cainwise.util;
import java.io.UnsupportedEncodingException;
public class Cipher_duicheng {
//密钥
private final static String key = "uiow92384!@#5^&*(-==9@@(==)";
//将一个字符串与一个字节进行计算,生成一个新字符串.
private static String pass(byte b,String str){
byte[] ee;
try {
ee = str.getBytes("ISO-8859-1");
for(int i = 0 ;i<ee.length;i++){
ee[i] = (byte)(ee[i] ^ b);
}
return new String(ee,"ISO-8859-1");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
return "";
}
}
//加密方法
public static String compose(String code){
String tcode = code;
for(int i=0;i<key.length();i++){
byte b = (byte)key.charAt(i);
tcode = pass(b,tcode);
}
return tcode;
}
//解密码算法
public static String parse(String code){
String tcode = code;
for(int i=key.length();i > 0;i--){
byte b = (byte)key.charAt(i-1);
tcode = pass(b,tcode);
}
return tcode;
}
}