Untitled
// Base64 解碼 AES 金鑰 $AES_key = base64_decode( $api_key ); // 產生 SHA256_HEX ( Payload ) $sha256Payload = hash( 'sha256', $payload, true ); // 產生隨機的 iv // $iv = str_repeat( chr( 0 ), 12 ); $iv = openssl_random_pseudo_bytes( 12 ); // $iv_HEX = bin2hex( $iv ); // 進行 AES-GCM 加密 >>>> 這一步出來的值和驗證的不同 $ciphertext = openssl_encrypt( $sha256Payload, 'aes-128-gcm', $AES_key, OPENSSL_RAW_DATA, $iv, $tag ); // 串接 ciphertext 和 iv,並將結果轉換為十六進位字串 $sp_checksum = bin2hex( $iv . $ciphertext );