求此程序编译结果

jzyslb 2013-12-02 08:54:57
小弟不懂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);
}
}
...全文
206 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
南猿北蛰 2013-12-03
  • 打赏
  • 举报
回复
输出结果为:skl7%dkre*j3uedOeE#W4E2t34UIu
jzyslb 2013-12-02
  • 打赏
  • 举报
回复
主程序 String password="3v3TaGU4x%2FkCGu0YufDbJ9cRhsAlhM3KXt789hPC3qUiuhI38yGoD6hHSeh6R34TGwnjYI6EApKXzDlj6%2BDvQQ%3D%3D"; DesSecret desSecret = new DesSecret(); String key = "Sx@!168#$%@As56"; password = desSecret.get3DESDecrypt(password, key); 我是想知道这个password通过程序之后的输出值
桃园闲人 2013-12-02
  • 打赏
  • 举报
回复
如果将注释部分代码放到for循环中运行结果如下: 进行3-DES加密后的内容: h%2FKEgH2MAOGpzy9sEhDBrjEbIrHPGQt07w1jcJsc%2BVq%2FmAk3NhbaUPYQCZBMlDTS 进行3-DES解密后的内容: erg$G##%k5DFI@#i3g$$SKG
桃园闲人 2013-12-02
  • 打赏
  • 举报
回复
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;
	}
以上方法中注释部分代码编译不过,将其注释后运行结果为: 进行3-DES加密后的内容: Wd88pNAfv5OVFvhMVyfS88lE85iZBbOvWpCM8iv%2FPOQAu4Y%2F5qMKV5BLFPLoVL8%2B 进行3-DES解密后的内容: erg$G##%k5DFI@#i3g$$SKG

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧