import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;import javax.crypto.Cipher;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.PBEKeySpec;
import javax.crypto.spec.PBEParameterSpec;import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;
public class TestJava
{
///_mthnew加密
public synchronized native static byte[] mthdo(byte abyte0[], int i, String s)
throws InternalError;
//_mthif 解密
public synchronized native static byte[] mthfor(byte abyte0[], int i, String s)
throws InternalError; public synchronized native byte[] mthif(byte abyte0[], String s)
throws InternalError;
//注册加密
public synchronized native static byte[] mthnew(byte abyte0[], int i, String s)
throws InternalError; public synchronized native byte[] mthtry(byte abyte0[], byte abyte1[], byte abyte2[], byte abyte3[], String s)
throws InternalError; public synchronized native boolean mthbyte(byte abyte0[], byte abyte1[], byte abyte2[], byte abyte3[], String s)
throws InternalError;
public static byte[] _mthnew(byte abyte0[])//解
{
return mthdo(abyte0,40, "bf-cfb"); }
public static byte[] _mthif(byte abyte0[]) //加
{
return mthfor(abyte0,40, "bf-cfb");
}
public static byte[] _mthif(byte abyte0[], int i, int l)//注册
{
byte abyte1[];
abyte1 = new byte[l];
System.arraycopy(abyte0, i, abyte1, 0, l);
return mthnew(abyte1, 0, "md5");
}
//姓名身份证加密
public static String ec(String s)throws Exception
{
byte _fldint[] = { -87, -101, -56, 50, 86, 53, -29, 3};
String Key="123!@#qweQWE/.,?><abc";
PBEParameterSpec pbeparameterspec = new PBEParameterSpec(_fldint,19);
PBEKeySpec pbekeyspec = new PBEKeySpec(Key.toCharArray());
SecretKeyFactory secretkeyfactory = SecretKeyFactory.getInstance("PBEWithMD5AndDES");
javax.crypto.SecretKey secretkey = secretkeyfactory.generateSecret(pbekeyspec);
Cipher cipher = Cipher.getInstance("PBEWithMD5AndDES");
cipher.init(Cipher.ENCRYPT_MODE, secretkey, pbeparameterspec);
byte abyte1[] = s.getBytes("UTF8");
byte abyte2[] = cipher.doFinal(abyte1);
BASE64Encoder BASE64Encoder = new BASE64Encoder();
return BASE64Encoder.encode(abyte2);
}
//姓名身份证解密
public static String ed(String s)throws Exception
{
String Key="123!@#qweQWE/.,?><abc";
byte _fldint[] = { -87, -101, -56, 50, 86, 53, -29, 3};
BASE64Decoder BASE64Decoder = new BASE64Decoder();
byte abyte9[] = BASE64Decoder.decodeBuffer(s);
PBEParameterSpec pbeparameterspec = new PBEParameterSpec(_fldint,19);
PBEKeySpec pbekeyspec = new PBEKeySpec(Key.toCharArray());
SecretKeyFactory secretkeyfactory = SecretKeyFactory.getInstance("PBEWithMD5AndDES");
javax.crypto.SecretKey secretkey = secretkeyfactory.generateSecret(pbekeyspec);
Cipher cipher = Cipher.getInstance("PBEWithMD5AndDES");
cipher.init(2, secretkey, pbeparameterspec);
byte abyte2[] = cipher.doFinal(abyte9);
return new String(abyte2, "UTF8");
}
//会员密码加密
public static String getEncryptString(String s)throws Exception
{
String s1;
BASE64Encoder BASE64Encoder = new BASE64Encoder();
s1 = BASE64Encoder.encode(_mthnew(s.getBytes()));
return s1;
}
//会员密码解密
public static String getDecryptString(String s)throws Exception
{
String s1;
BASE64Decoder BASE64Decoder = new BASE64Decoder();
s1 = new String(_mthif(BASE64Decoder.decodeBuffer(s)));
return s1;
}
//后台帐号密码加密MD5+Base64
public static byte[] encrypt(String data)
{
if (data==null || data.trim().length()==0) {
return data.getBytes();
}
try {
MessageDigest md = MessageDigest.getInstance("MD5");
md.reset(); byte[] encryptData = md.digest(data.getBytes("iso8859-1"));
return encryptData;
}
catch (NoSuchAlgorithmException ex) {
return data.getBytes();
}catch (UnsupportedEncodingException ex) {
return data.getBytes();
}
} public static void main(String args[]) throws Exception
{
String S1="123456";
String CID="用户名身份证";
//会员密码
System.out.println("会员密码加密(a.dll):123456="+ getEncryptString(S1));
System.out.println("会员密码解密(a.dll):ETLCw4cN="+ getDecryptString("ETLCw4cN")); //用户名身份证加解密
System.out.println(CID+"(PBEWithMD5AndDES)加密 = "+ ec(CID));
System.out.println("CuHj1foJK/Mmja+E0DTEpldSLomDv+Uj 解密 = "+ ed("CuHj1foJK/Mmja+E0DTEpldSLomDv+Uj")); BASE64Encoder BASE64Encoder = new BASE64Encoder();
//后台帐号密码加密
System.out.println( "后台帐号密码加密(MD5+BASE64):"+BASE64Encoder.encode(encrypt(S1)));
System.exit(0);
}
static
{
System.loadLibrary("a");
} }要求有2一个文本框,第一个框里输入未加密数据一按按扭第二个里显示加密数据(用户名身份证)
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货