openssl_encrypt 有时无法加密成功? 求神问卜.

<?php

//$key should have been previously generated in a cryptographically safe way, like openssl_random_pseudo_bytes
$key = 'AABBCCEEDD';
$plaintext = "sadfqwerasd333353";  //错误
$plaintext = 'TT000000000000000';  // 错误
$plaintext = '1';   //错误.
$plaintext = '0123456789123456';   //OK 

$cipher = "des-ecb";
if (in_array($cipher, openssl_get_cipher_methods()))
{
    $ivlen = openssl_cipher_iv_length($cipher);
    $iv = openssl_random_pseudo_bytes($ivlen);
    $ciphertext = openssl_encrypt($plaintext, $cipher, $key, OPENSSL_RAW_DATA|OPENSSL_ZERO_PADDING, $iv);
    //store $cipher, $iv, and $tag for decryption later
    $original_plaintext = openssl_decrypt($ciphertext, $cipher, $key, OPENSSL_RAW_DATA|OPENSSL_ZERO_PADDING, $iv);
    var_dump($original_plaintext)."\n";
}else{
    echo '<pre>';
    print_r(openssl_get_cipher_methods());
}
阅读 1.6k
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题