微信获取授权用户手机号
用户登录获取用户的sessionKey
这一步主要是用JSCODE通过微信接口获得
解密
public String decodePhone(String encryptedData, String iv, String sessionKey){
try {
byte[] sessionKeyBytes = Base64.decode(sessionKey);
byte[] encryptedDataBytes = Base64.decode(encryptedData);
byte[] ivBytes = Base64.decode(iv);
Security.addProvider(new BouncyCastleProvider());
SecretKeySpec skeySpec = new SecretKeySpec(sessionKeyBytes, "AES");
AlgorithmParameters parameters = AlgorithmParameters.getInstance("AES");
parameters.init(new IvParameterSpec(ivBytes, 0, INIT_VECTOR_LENGTH));
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5PADDING");
cipher.init(Cipher.DECRYPT_MODE, skeySpec, new IvParameterSpec(ivBytes, 0, INIT_VECTOR_LENGTH));
byte[] decrypted = cipher.doFinal(encryptedDataBytes);
if (null != decrypted && decrypted.length > 0) {
String result = new String(decrypted, "UTF-8");
return result;
}
} catch (Exception ex) {
ex.printStackTrace();
}
return null;
}