代码之家  ›  专栏  ›  技术社区  ›  Tarek Adam

在没有mcrypt的情况下,如何使用PHP解密ClickBank通知数据?

  •  1
  • Tarek Adam  · 技术社区  · 8 年前

    多年来,Mcrypt一直被弃用,最终退出了php。不幸的是,我需要解码ClickBank中的加密数据,他们的文档只提供mcrypt解决方案。

    这是从他们的文件中删去的。没有mcrypt\u decode(),我怎么能做到这一点?

    $secretKey = "YOUR SECRET KEY"; // secret key from your ClickBank account
    
    // get JSON from raw body...
    $message = json_decode(file_get_contents('php://input'));
    
    // Pull out the encrypted notification and the initialization vector for
    // AES/CBC/PKCS5Padding decryption
    $encrypted = $message->{'notification'};
    $iv        = $message->{'iv'};
    error_log("IV: $iv");
    
    // decrypt the body...
    $decrypted = trim(mcrypt_decrypt(MCRYPT_RIJNDAEL_128,
                                 substr(sha1($secretKey), 0, 32),
                                 base64_decode($encrypted),
                                 MCRYPT_MODE_CBC,
                                 base64_decode($iv)), "\0..\32");
    error_log("Decrypted: $decrypted");
    
    ////UTF8 Encoding, remove escape back slashes, and convert the decrypted string to a JSON object...
    $sanitizedData = utf8_encode(stripslashes($decrypted));
    $order         = json_decode($decrypted);
    
    1 回复  |  直到 8 年前
        1
  •  1
  •   Tarek Adam    8 年前
    $notification_array = json_decode(utf8_encode(stripslashes(trim(openssl_decrypt($encrypted,
                                     'AES-256-CBC',
                                     substr(sha1($secretKey), 0, 32),
                                     OPENSSL_ZERO_PADDING, base64_decode($iv)), "\0..\32"))), true);