我以前在以前的PHP 5.6版本中使用“ mcrypt- *”来解码响应,但现在在PHP 7.2版本中却已弃用,因为我正在使用openSSL方法。但是它运行不正常,希望我丢失了一些东西。
theme: ThemeData(
brightness: Brightness.dark,
primaryColor: Colors.pink,
backgroundColor: Colors.grey[900],
textSelectionColor: Colors.pink,
textSelectionHandleColor: Colors.pink[700],
textTheme: TextTheme(
body1: TextStyle(color: Colors.white),
),
),
PHP 5.6正常工作
$value="###lllljG5ZOibDGtlL gcQLAtTQUnCJ/bE2glWsL1WKVPdC22c9GtGe/Npx9Uv9IYaszOAVXB4T9s7Hsss/2XpZ9oisx5M4jeV7RK2S/JrBt2E4GEcDGwuJs6NhkKV8hdOcU tmkJLxO3OJ OgVbqrT6a4v5RE7w eP zvQwZyAR5cYCKUYomou9mL/pvfLbe RrBe5ZnMQmUrD6cwUxEE/inikMvIb4K7HI fVPid N B3iPnIYQna6/v9W5A0kslBj6BBDjVXJabwmCSDVxbArm0GDNseWoQAEa4BMxYitqP6cVTxL5Kri8xbAKCW5/unnYnudkHQjNJWW7LuiwDxsBqwQv8D/R/Ff/joFW6q0 muI16/CfIoFnYAyAJWNlKCX9";
$value = urldecode($value);
$value = str_replace(" ", "+", $value);
$abc = triple_decrypt($value);
print_r($abc);
PHP 7.2
function triple_decrypt($input){
$key = "thisis87658748639testkey";
$input = base64_decode($input);
$td = mcrypt_module_open(MCRYPT_TripleDES, "", MCRYPT_MODE_ECB, "");
$iv = mcrypt_create_iv(mcrypt_enc_get_iv_size ($td), MCRYPT_RAND);
mcrypt_generic_init($td, $key, $iv);
$pwd = trim(mdecrypt_generic($td, $input), "\x00..\x0F");
mcrypt_generic_end($td);
return $pwd;
}
答案 0 :(得分:2)
openssl 使用PKCS7填充和 mcrypt 零填充[0] [1] [2]。要使用 openssl 解密密文,必须禁用 openssl 的填充,并且必须删除 mcrypt 的零填充字节:
function triple_decrypt($input){
$key = "thisis87658748639testkey";
$cipher = "des-ede3";
$decrypted = openssl_decrypt($input, $cipher, $key, $options=OPENSSL_ZERO_PADDING); // Disable openssl's PKCS7-padding
$unpadded = trim($decrypted, "\x00..\x0F"); // Remove mcrypt's Zero-padding bytes
return $unpadded;
}
但是,关于加密和解密的重新实现,请注意以下几点:ECB是一种不安全的模式[3]。相反,应该使用[4] [5]使用CBC甚至更好的GCM。建议[6]代替现代的更快的标准AES,而不是Triple-DES。零填充是不可靠的,应改用PKCS7填充。
此外, mcrypt 代码在某种程度上是不一致的:
答案 1 :(得分:1)
您可以使用openssl()
function encryptIt($q) {
$cryptKey = 'YourProjectname'; //any string
$encryptionMethod = "AES-256-CBC";
$secretHash = "25c6c7rr35b9979b151f0205cd13b0vv"; // any hash
//To encrypt
$qEncoded = openssl_encrypt($q, $encryptionMethod, $secretHash);
return $qEncoded;
}
function decryptIt($q) {
$cryptKey = 'YourProjectname'; //any string
$encryptionMethod = "AES-256-CBC";
$secretHash = "25c6c7rr35b9979b151f0205cd13b0vv"; // any hash
//To Decrypt
$qDecoded = openssl_decrypt($q, $encryptionMethod, $secretHash);
return $qDecoded;
}
$encryptedstring = encryptIt('TEST');
echo "<br/>";
echo decryptIt($encryptedstring);