文章來(lái)源--http://jkvast.iteye.com/blog/1175708(如作者不愿被引用,聯(lián)系必刪除,謝謝)
由于58同城在頁(yè)面上抓取二手房信息的時(shí)候,用戶的聯(lián)系電話是圖片的,本人水平關(guān)系無(wú)法進(jìn)行很好的識(shí)別,所以轉(zhuǎn)為抓取其android客戶端比較容易,之前都是好好的,最近發(fā)現(xiàn)其升級(jí)到1.3.0.0后手機(jī)號(hào)碼進(jìn)行了加密,所以直接反編譯其android客戶端,查到其用的是des加密,而且加密的key很容易就拿到,下面貼出解密方法。(des加解密比較簡(jiǎn)單下面貼出來(lái))
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; //這個(gè)key如果有需要請(qǐng)反編譯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();
}
}
很久沒(méi)寫博,上來(lái)溜溜,我是firstep
補(bǔ)充
時(shí)至今日,58已經(jīng)不在des
58電話接口
通過(guò)app進(jìn)行抓包,可以很清楚看到58app電話接口是沒(méi)有加簽名的,這個(gè)設(shè)計(jì)也許是因?yàn)?8認(rèn)為無(wú)傷大雅,也有可能是歷史原因,app版本強(qiáng)制升級(jí)用戶體驗(yàn)不好了,至于真實(shí)原因無(wú)從得知。