由於58同城在頁面上抓取二手房資訊的時候,使用者的聯絡電話是圖片的,本人水平關係無法進行很好的識別,所以轉為抓取其android用戶端比較容易,之前都是好好的,最近發現其升級到1.3.0.0後手機號碼進行了加密,所以直接反編譯其android用戶端,查到其用的是des加密,而且加密的key很容易就拿到,下面貼出解密方法。(des加解密比較簡單下面貼出來)
Java代碼
import java.security.SecureRandom;
import javax.crypto.Cipher;
import javax.crypto.SecretKey;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.DESKeySpec;
public class Decode458 {
static byte[] key = null; //這個key如果有需要請反編譯58用戶端擷取這裡不便貼出
public static void main(String[] args) throws Exception {
System.out.println(new String(Decode458.decode(Decode458.convertHexString("002E674657AE8239982087DCB2E6A99B"))));
System.out.println(Decode458.toHexString(Decode458.encode("13219863008".getBytes())));
}
public static byte[] decode(byte[] paramArrayOfByte) {
try {
SecureRandom localSecureRandom = new SecureRandom();
DESKeySpec localDESKeySpec = new DESKeySpec(key);
SecretKey localSecretKey = SecretKeyFactory.getInstance("DES")
.generateSecret(localDESKeySpec);
Cipher localCipher = Cipher.getInstance("DES");
localCipher.init(2, localSecretKey, localSecureRandom);
return localCipher.doFinal(paramArrayOfByte);
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
public static byte[] encode(byte[] paramArrayOfByte) {
try {
SecureRandom localSecureRandom = new SecureRandom();
DESKeySpec localDESKeySpec = new DESKeySpec(key);
SecretKey localSecretKey = SecretKeyFactory.getInstance("DES")
.generateSecret(localDESKeySpec);
Cipher localCipher = Cipher.getInstance("DES");
localCipher.init(1, localSecretKey, localSecureRandom);
return localCipher.doFinal(paramArrayOfByte);
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
public static byte[] convertHexString(String text) {
byte digest[] = new byte[text.length() / 2];
for (int i = 0; i < digest.length; i++) {
String byteString = text.substring(2 * i, 2 * i + 2);
int byteValue = Integer.parseInt(byteString, 16);
digest[i] = (byte) byteValue;
}
return digest;
}
public static String toHexString(byte b[]) {
StringBuffer hexString = new StringBuffer();
for (int i = 0; i < b.length; i++) {
String plainText = Integer.toHexString(0xff & b[i]);
if (plainText.length() < 2)
plainText = "0" + plainText;
hexString.append(plainText);
}
return hexString.toString();
}
}
作者“jkvast”