Java 的这段 cipher AES 解密算法,求个 PHP 版本

holystrike3天前0

这是某应用给的 Java 的解密算法

import org.apache.commons.codec.binary.Base64;import javax.crypto.Cipher;import javax.crypto.spec.SecretKeySpec;import java.nio.charset.StandardCharsets;public class AESUtils {    public static String aesDecrypt(String str, String key) throws Exception {        Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");        cipher.init(Cipher.DECRYPT_MODE, new SecretKeySpec(key.getBytes(StandardCharsets.UTF_8), "AES"));        byte[] bytes = Base64.decodeBase64(str);        bytes = cipher.doFinal(bytes);        return new String(bytes, StandardCharsets.UTF_8);    }}

我尝试了多种,都无法解出来

参考加密数据(解密秘钥 1234567890123456 )

E4M54v2CbwnbdG+quqWwgFGI5dgx3shx2gGZRiihvkQQLgbH12Y9/dJXO1/7H7QLL3H9fstismlYMLQrZxShEyknFJcLG96HbG4Cx/7gq4YMXgZJDI9Qvm1sH6H4arIHaPTSbHTkfaYo7fo6Sc3lwBMOpJHi33Os5u7DobPmqkzkuyoRxbTD4mZaSYleDcYuouQTdma+rubH5PPzg0+R09XsEHWkgF6cc+Ylh2w0N6590eJDNdQvoI4m7eSiWQCJo5nN5zXj/2QeQcYwIfdpmQ==

应得到的解密数据(解密秘钥 1234567890123456 )

{ "id": "dbe8970a-53a7-165c-7339-02c55bbddea5", "appKey": "FQa4kEGD", "appId": "34526534673", "msgType": "notice", "time": "1603698652093", "bizContent": {  "name:": "测试",  "value": "测试" }}

无奈不大懂 java ,需要用 PHP 来进行解密

求双修人士改为 PHP 可以用版本,谢!

最新回复 (4)
  • DrX3天前
    引用2
    50 块钱解君愁
  • leadfast3天前
    引用3
    随便搜的一个就可以的啊
    ```
    function decrypt($str, $key)
    {
    $decrypted = openssl_decrypt($str, 'AES-128-ECB', $key, OPENSSL_ZERO_PADDING);
    $dec_s = strlen($decrypted);
    $padding = ord($decrypted[$dec_s - 1]);
    $decrypted = substr($decrypted, 0, -$padding);
    return $decrypted;
    }
    $str = "E4M54v2CbwnbdG+quqWwgFGI5dgx3shx2gGZRiihvkQQLgbH12Y9/dJXO1/7H7QLL3H9fstismlYMLQrZxShEyknFJcLG96HbG4Cx/7gq4YMXgZJDI9Qvm1sH6H4arIHaPTSbHTkfaYo7fo6Sc3lwBMOpJHi33Os5u7DobPmqkzkuyoRxbTD4mZaSYleDcYuouQTdma+rubH5PPzg0+R09XsEHWkgF6cc+Ylh2w0N6590eJDNdQvoI4m7eSiWQCJo5nN5zXj/2QeQcYwIfdpmQ==";
    $res = decrypt($str, "1234567890123456");
    ```
  • DrX3天前
    引用4
    openssl_decrypt(base64_decode('E4M54v2CbwnbdG+quqWwgFGI5dgx3shx2gGZRiihvkQQLgbH12Y9/dJXO1/7H7QLL3H9fstismlYMLQrZxShEyknFJcLG96HbG4Cx/7gq4YMXgZJDI9Qvm1sH6H4arIHaPTSbHTkfaYo7fo6Sc3lwBMOpJHi33Os5u7DobPmqkzkuyoRxbTD4mZaSYleDcYuouQTdma+rubH5PPzg0+R09XsEHWkgF6cc+Ylh2w0N6590eJDNdQvoI4m7eSiWQCJo5nN5zXj/2QeQcYwIfdpmQ=='), 'AES-128-ECB', '1234567890123456', OPENSSL_RAW_DATA);
    ```
    {
    "id": "dbe8970a-53a7-165c-7339-02c55bbddea5",
    "appKey": "FQa4kEGD",
    "appId": "34526534673",
    "msgType": "notice",
    "time": "1603698652093",
    "bizContent": {
    "name:": "测试",
    "value": "测试"
    }
    }
    ```
  • 楼主holystrike2天前
    引用5
    感谢楼上各佬,管用!
  • 游客
    6
返回