58同城android客户端手机号码解密方法

由于58同城在页面上抓取二手房信息的时候,用户的联系电话是图片的,本人水平关系无法进行很好的识别,所以转为抓取其android客户端比较容易,之前都是好好的,最近发现其升级到1.3.0.0后手机号码进行了加密,所以直接反编译其android客户端,查到其用的是des加密,而且加密的key很容易就拿到,下面贴出解密方法。(des加解密比较简单下面贴出来)

 

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();
	}
}

 

很久没写博,上来溜溜,我是firstep

本文转载自:http://hi.baidu.com/alvin4u/blog/item/d2c5ad1b2c7d8938dd5401a5.html

 

你可能感兴趣的:(android)