<?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());
}