运行一下代码 通过日志查看获取方法
public static void main(String[] args) {
try {
String str = "d41051ab3934a61c9230ce951313dd6ef17e0ad48ba89b2bd00dbfbdfe2585412c0b4b0a94d86bb417eaf27a0391be1c0f992a5519d2f3825d24fd128c92643e0793e1e4e64fbd10042742cf5d6eb8e7ecad5cb9406fd77e7ad3bbebe89b1c0857ad31da9272740fe86e89b3fc91931d";
EncryptDES des = new EncryptDES();// 使用默认密钥
byte[] decrypt = des.decryptCipher.doFinal(hexStr2ByteArr(str));
System.out.println("获取文章源码的方法:" + new String(decrypt));
} catch (Exception e) {
e.printStackTrace();
}
}
private static String strDefaultKey = "sougit.com";
private Cipher decryptCipher = null;
public EncryptDES() throws Exception {
this(strDefaultKey);
}
public EncryptDES(String strKey) throws Exception {
Key key = getKey(strKey.getBytes());
decryptCipher = Cipher.getInstance("DES");
decryptCipher.init(Cipher.DECRYPT_MODE, key);
}
public static byte[] hexStr2ByteArr(String strIn) throws Exception {
byte[] arrB = strIn.getBytes();
int iLen = arrB.length;
byte[] arrOut = new byte[iLen / 2];
for (int i = 0; i < iLen; i = i + 2) {
String strTmp = new String(arrB, i, 2);
arrOut[i / 2] = (byte) Integer.parseInt(strTmp, 16);
}
return arrOut;
}
private Key getKey(byte[] arrBTmp) throws Exception {
byte[] arrB = new byte[8];
for (int i = 0; i < arrBTmp.length && i < arrB.length; i++) {
arrB[i] = arrBTmp[i];
}
Key key = new javax.crypto.spec.SecretKeySpec(arrB, "DES");
return key;
}