记一次倒腾java和php通用AES解密过程
分析了一个apk文件,需要获取该apk接口返回的数据密文的结果。。
于是有了这个记录。。
贴一下反编译后的java代码
//
// Decompiled by Jadx - 841ms
//
package com.tgproxy.finder.appManagers;
import android.util.Base64;
import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import javax.crypto.Cipher;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
public class MoreApps {
public MoreApps() {
}
public static String md5(String str) throws NoSuchAlgorithmException {
return new BigInteger(1, MessageDigest.getInstance("MD5").digest(str.getBytes())).toString(16);
}
public static String adds(String str) {
try {
SecretKeySpec secretKeySpec = new SecretKeySpec(md5("naaxaebfdfndsgdfgdfshb").getBytes(), "AES");
IvParameterSpec ivParameterSpec = new IvParameterSpec("mannanamodoosdam".getBytes());
Cipher instance = Cipher.getInstance("AES/CFB8/NoPadding");
instance.init(2, secretKeySpec, ivParameterSpec);
return new String(instance.doFinal(Base64.decode(str.getBytes(), 0)), "UTF8");
} catch (Exception unused) {
return null;
}
}
}
以上是java的解密流程,在写php解密流程的时候用AES-128-ECB,居然解密不出来。。
密文和偏移量都是正确的!那就只有一个可能,解密用的方法不正确!
所幸,openssl_get_cipher_methods()提供了所有的可用密码方法的列表,那么就简单粗暴的遍历一下~~~~
$secretKey = md5('naaxaebfdfndsgdfgdfshb');
$initialVector = 'mannanamodoosdam';
$types = openssl_get_cipher_methods();
foreach ($types as $type) {
echo openssl_decrypt(base64_decode($secret), $type, $secretKey, OPENSSL_RAW_DATA, $initialVector);
}
嗯,最终在方法为AES-256-CFB8时,跑出解密后的数据!完事!