求此程序编译结果
小弟不懂JAVA,也没用环境,程序没问题,
求哪位老大帮忙给运行一下
我想知道通过解密之后的 password的值是多少
主程序
String password="3v3TaGU4x%2FkCGu0YufDbJ9cRhsAlhM3KXt789hPC3qUiuhI38yGoD6hHSeh6R34TGwnjYI6EApKXzDlj6%2BDvQQ%3D%3D";
DesSecret desSecret = new DesSecret();
String key = "Sx@!168#$%@As56";
password = desSecret.get3DESDecrypt(password, key);
调用DesSecret.class
package com.common;
import java.io.PrintStream;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.security.MessageDigest;
import javax.crypto.Cipher;
import javax.crypto.SecretKey;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.DESedeKeySpec;
import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;
public class DesSecret
{
public String key;
public DesSecret()
{
this.key = "eproapx";
}
private byte[] md5(String strSrc)
{
byte[] returnByte = (byte[])null;
try
{
MessageDigest md5 = MessageDigest.getInstance("MD5");
returnByte = md5.digest(strSrc.getBytes("GBK"));
}
catch (Exception e)
{
e.printStackTrace();
}
return returnByte;
}
private byte[] getEnKey(String spKey)
{
byte[] desKey = (byte[])null;
try
{
byte[] desKey1 = md5(spKey);
desKey = new byte[24];
for (int i = 0; (i < desKey1.length) && (i < 24); i++) {
desKey[i] = desKey1[i];
}
if (i < 24)
{
desKey[i] = 0;
i++;
}
}
catch (Exception e)
{
e.printStackTrace();
}
return desKey;
}
public String getBase64Encode(byte[] src)
{
String requestValue = "";
try
{
BASE64Encoder base64en = new BASE64Encoder();
requestValue = base64en.encode(src);
}
catch (Exception e)
{
e.printStackTrace();
}
return requestValue;
}
private String filter(String str)
{
String output = null;
StringBuffer sb = new StringBuffer();
for (int i = 0; i < str.length(); i++)
{
int asc = str.charAt(i);
if ((asc != 10) && (asc != 13)) {
sb.append(str.subSequence(i, i + 1));
}
}
output = new String(sb);
return output;
}
public String getURLEncode(String src)
{
String requestValue = "";
try
{
requestValue = URLEncoder.encode(src);
}
catch (Exception e)
{
e.printStackTrace();
}
return requestValue;
}
public String getURLDecoderdecode(String src)
{
String requestValue = "";
try
{
requestValue = URLDecoder.decode(src);
}
catch (Exception e)
{
e.printStackTrace();
}
return requestValue;
}
public byte[] Encrypt(byte[] src, byte[] enKey)
{
byte[] encryptedData = (byte[])null;
try
{
DESedeKeySpec dks = new DESedeKeySpec(enKey);
SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DESede");
SecretKey key = keyFactory.generateSecret(dks);
Cipher cipher = Cipher.getInstance("DESede");
cipher.init(1, key);
encryptedData = cipher.doFinal(src);
}
catch (Exception e)
{
e.printStackTrace();
}
return encryptedData;
}
public String deCrypt(byte[] debase64, String spKey)
{
String strDe = null;
Cipher cipher = null;
try
{
cipher = Cipher.getInstance("DESede");
byte[] key = getEnKey(spKey);
DESedeKeySpec dks = new DESedeKeySpec(key);
SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DESede");
SecretKey sKey = keyFactory.generateSecret(dks);
cipher.init(2, sKey);
byte[] ciphertext = cipher.doFinal(debase64);
strDe = new String(ciphertext, "UTF-16LE");
}
catch (Exception ex)
{
strDe = "";
ex.printStackTrace();
}
return strDe;
}
public String get3DESEncrypt(String src, String spkey)
{
String requestValue = "";
try
{
byte[] enKey = getEnKey(spkey);
byte[] src2 = src.getBytes("UTF-16LE");
byte[] encryptedData = Encrypt(src2, enKey);
String base64String = getBase64Encode(encryptedData);
String base64Encrypt = filter(base64String);
requestValue = getURLEncode(base64Encrypt);
}
catch (Exception e)
{
e.printStackTrace();
}
return requestValue;
}
public String get3DESDecrypt(String src, String spkey)
{
String requestValue = "";
try
{
String URLValue = getURLDecoderdecode(src);
BASE64Decoder base64Decode = new BASE64Decoder();
byte[] base64DValue = base64Decode.decodeBuffer(URLValue);
requestValue = deCrypt(base64DValue, spkey);
}
catch (Exception e)
{
e.printStackTrace();
}
return requestValue;
}
public static void main(String[] args)
{
DesSecret test = new DesSecret();
String oldString = "erg$G##%k5DFI@#i3g$$SKG";
String key = "Sx@!168#$%@As56";
String reValue = test.get3DESEncrypt(oldString, key);
reValue = reValue.trim().intern();
System.out.println(new StringBuilder("进行3-DES加密后的内容: ").append(reValue));
String reValue2 = test.get3DESDecrypt(reValue, key);
System.out.println("进行3-DES解密后的内容: " + reValue2);
}
}
[解决办法]
private byte[] getEnKey(String spKey) {
byte[] desKey = (byte[]) null;
try {
byte[] desKey1 = md5(spKey);
desKey = new byte[24];
for (int i = 0; (i < desKey1.length) && (i < 24); i++) {
desKey[i] = desKey1[i];
}
//if (i < 24) {
//desKey[i] = 0;
//i++;
//}
} catch (Exception e) {
e.printStackTrace();
}
return desKey;
}