我已经完成了通过API将公司系统集成到外部系统的任务 . 当我读到API时,它声明应该使用MD5和Triple Des Encryption加密数据,所以我做了一些关于如何做的研究 .

// Here's the credentials to be used for encryption.

$key = 'dEvu4MHkqz7mRgeqmB1mQEXi';
$iv  = "avz9bUNx";

在加密之前,数据应格式化为JSON字符串 .

$params = array(
        'Number' => '+11177109886' // example
    );

$text = json_encode($params);

之后我做了一些代码来加密它 .

function apiEncode($text, $key, $iv)
{
    // to append string with trailing characters as for PKCS7 padding scheme
    $block = mcrypt_get_block_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_CBC);
    $padding = $block - (strlen($text) % $block);
    $text .= str_repeat(chr($padding), $padding);

    $crypttext = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $key, $text, MCRYPT_MODE_CBC, $iv);
    return base64_encode($crypttext);
}

我得到的错误是 .

警告:mcrypt_encrypt():接收大小为0的初始化向量,但第20行的/Applications/XAMPP/xamppfiles/htdocs/dapsapi/rdremit.php中的此加密模式需要大小为32