亚洲激情专区-91九色丨porny丨老师-久久久久久久女国产乱让韩-国产精品午夜小视频观看

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

php中如何將mcrypt轉換成openssl?

發布時間:2020-05-22 18:09:24 來源:億速云 閱讀:408 作者:鴿子 欄目:編程語言

例如

public function desEncrypt($str,$key) {
     $iv = $key;
         $size = mcrypt_get_block_size ( MCRYPT_DES, MCRYPT_MODE_CBC );
         $str = $this->_pkcs5_pad ( $str, $size );
         return strtoupper( bin2hex( mcrypt_encrypt(MCRYPT_DES, $key, $str, MCRYPT_MODE_CBC, $iv ) ) );
     }
     
public function desDecrypt($str,$key) {
     $iv = $key;
         $strBin = $this->_hex2bin( strtolower( $str ) );
         $str = mcrypt_decrypt( MCRYPT_DES, $key, $strBin, MCRYPT_MODE_CBC, $iv );
         $str = $this->_pkcs5_unpad( $str );
         return $str;
     }
 
private function _pkcs5_pad($text,$block=8){
         $pad = $block - (strlen($text) % $block);
         return $text . str_repeat(chr($pad), $pad);
     }
     
private function _pkcs5_unpad($text) {
        $pad = ord($text{strlen($text)-1});
        if ($pad > strlen($text)) return $text;
        if (strspn($text, chr($pad), strlen($text) - $pad) != $pad) return $text;
        return substr($text, 0, -1 * $pad);
     }

替換后:

//要改的加密
    public function desEncrypt($str,$key) {
      //   $b = openssl_get_cipher_methods();
      //   echo '<pre>';
      //   print_r($b);
     $iv = $key;
      //    $size = mcrypt_get_block_size ( MCRYPT_DES, MCRYPT_MODE_CBC );
      //    var_dump($size);exit;
      //    $str = $this->_pkcs5_pad ( $str, $size );
 
         // return strtoupper( bin2hex( mcrypt_encrypt(MCRYPT_DES, $key, $str, MCRYPT_MODE_CBC, $iv ) ) );
        $data = openssl_encrypt($str,"DES-CBC",$key,OPENSSL_RAW_DATA,$iv);
        $data = strtolower(bin2hex($data));
        return $data;
     }
     
    //要改的解密
    public function desDecrypt($str,$key) {
     $iv = $key;
      //    $strBin = $this->_hex2bin( strtolower( $str ) );
      //    $str = mcrypt_decrypt( MCRYPT_DES, $key, $strBin, MCRYPT_MODE_CBC, $iv );
      //    $str = $this->_pkcs5_unpad( $str );
      //    return $str;
        return openssl_decrypt (hex2bin($str), 'DES-CBC', $key, OPENSSL_RAW_DATA,$iv);
     }

這些網上都有,在作者使用的過程中因為使用的是MCRYPT_DES,無法得知openssl對應的是那種加密方式,所以通過手冊找到了openssl_get_cipher_methods();該方法可以找出openssl支持的所有方法,進行替換即可。

echo '<pre>';
$a = openssl_get_cipher_methods();
print_r($a);
 
Array
(
    [0] => AES-128-CBC
    [1] => AES-128-CFB
    [2] => AES-128-CFB1
    [3] => AES-128-CFB8
    [4] => AES-128-CTR
    [5] => AES-128-ECB
    [6] => AES-128-OFB
    [7] => AES-128-XTS
    [8] => AES-192-CBC
    [9] => AES-192-CFB
    [10] => AES-192-CFB1
    [11] => AES-192-CFB8
    [12] => AES-192-CTR
    [13] => AES-192-ECB
    [14] => AES-192-OFB
    [15] => AES-256-CBC
    [16] => AES-256-CFB
    [17] => AES-256-CFB1
    [18] => AES-256-CFB8
    [19] => AES-256-CTR
    [20] => AES-256-ECB
    [21] => AES-256-OFB
    [22] => AES-256-XTS
    [23] => BF-CBC
    [24] => BF-CFB
    [25] => BF-ECB
    [26] => BF-OFB
    [27] => CAMELLIA-128-CBC
    [28] => CAMELLIA-128-CFB
    [29] => CAMELLIA-128-CFB1
    [30] => CAMELLIA-128-CFB8
    [31] => CAMELLIA-128-ECB
    [32] => CAMELLIA-128-OFB
    [33] => CAMELLIA-192-CBC
    [34] => CAMELLIA-192-CFB
    [35] => CAMELLIA-192-CFB1
    [36] => CAMELLIA-192-CFB8
    [37] => CAMELLIA-192-ECB
    [38] => CAMELLIA-192-OFB
    [39] => CAMELLIA-256-CBC
    [40] => CAMELLIA-256-CFB
    [41] => CAMELLIA-256-CFB1
    [42] => CAMELLIA-256-CFB8
    [43] => CAMELLIA-256-ECB
    [44] => CAMELLIA-256-OFB
    [45] => CAST5-CBC
    [46] => CAST5-CFB
    [47] => CAST5-ECB
    [48] => CAST5-OFB
    [49] => DES-CBC
    [50] => DES-CFB
    [51] => DES-CFB1
    [52] => DES-CFB8
    [53] => DES-ECB
    [54] => DES-EDE
    [55] => DES-EDE-CBC
    [56] => DES-EDE-CFB
    [57] => DES-EDE-OFB
    [58] => DES-EDE3
    [59] => DES-EDE3-CBC
    [60] => DES-EDE3-CFB
    [61] => DES-EDE3-CFB1
    [62] => DES-EDE3-CFB8
    [63] => DES-EDE3-OFB
    [64] => DES-OFB
    [65] => DESX-CBC
    [66] => IDEA-CBC
    [67] => IDEA-CFB
    [68] => IDEA-ECB
    [69] => IDEA-OFB
    [70] => RC2-40-CBC
    [71] => RC2-64-CBC
    [72] => RC2-CBC
    [73] => RC2-CFB
    [74] => RC2-ECB
    [75] => RC2-OFB
    [76] => RC4
    [77] => RC4-40
    [78] => RC4-HMAC-MD5
    [79] => SEED-CBC
    [80] => SEED-CFB
    [81] => SEED-ECB
    [82] => SEED-OFB
    [83] => aes-128-cbc
    [84] => aes-128-cfb
    [85] => aes-128-cfb1
    [86] => aes-128-cfb8
    [87] => aes-128-ctr
    [88] => aes-128-ecb
    [89] => aes-128-gcm
    [90] => aes-128-ofb
    [91] => aes-128-xts
    [92] => aes-192-cbc
    [93] => aes-192-cfb
    [94] => aes-192-cfb1
    [95] => aes-192-cfb8
    [96] => aes-192-ctr
    [97] => aes-192-ecb
    [98] => aes-192-gcm
    [99] => aes-192-ofb
    [100] => aes-256-cbc
    [101] => aes-256-cfb
    [102] => aes-256-cfb1
    [103] => aes-256-cfb8
    [104] => aes-256-ctr
    [105] => aes-256-ecb
    [106] => aes-256-gcm
    [107] => aes-256-ofb
    [108] => aes-256-xts
    [109] => bf-cbc
    [110] => bf-cfb
    [111] => bf-ecb
    [112] => bf-ofb
    [113] => camellia-128-cbc
    [114] => camellia-128-cfb
    [115] => camellia-128-cfb1
    [116] => camellia-128-cfb8
    [117] => camellia-128-ecb
    [118] => camellia-128-ofb
    [119] => camellia-192-cbc
    [120] => camellia-192-cfb
    [121] => camellia-192-cfb1
    [122] => camellia-192-cfb8
    [123] => camellia-192-ecb
    [124] => camellia-192-ofb
    [125] => camellia-256-cbc
    [126] => camellia-256-cfb
    [127] => camellia-256-cfb1
    [128] => camellia-256-cfb8
    [129] => camellia-256-ecb
    [130] => camellia-256-ofb
    [131] => cast5-cbc
    [132] => cast5-cfb
    [133] => cast5-ecb
    [134] => cast5-ofb
    [135] => des-cbc
    [136] => des-cfb
    [137] => des-cfb1
    [138] => des-cfb8
    [139] => des-ecb
    [140] => des-ede
    [141] => des-ede-cbc
    [142] => des-ede-cfb
    [143] => des-ede-ofb
    [144] => des-ede3
    [145] => des-ede3-cbc
    [146] => des-ede3-cfb
    [147] => des-ede3-cfb1
    [148] => des-ede3-cfb8
    [149] => des-ede3-ofb
    [150] => des-ofb
    [151] => desx-cbc
    [152] => id-aes128-GCM
    [153] => id-aes192-GCM
    [154] => id-aes256-GCM
    [155] => idea-cbc
    [156] => idea-cfb
    [157] => idea-ecb
    [158] => idea-ofb
    [159] => rc2-40-cbc
    [160] => rc2-64-cbc
    [161] => rc2-cbc
    [162] => rc2-cfb
    [163] => rc2-ecb
    [164] => rc2-ofb
    [165] => rc4
    [166] => rc4-40
    [167] => rc4-hmac-md5
    [168] => seed-cbc
    [169] => seed-cfb
    [170] => seed-ecb
    [171] => seed-ofb
)

以上就是php7.2中mcrypt轉openssl的方法詳解的詳細內容,更多請關注億速云其它相關文章!

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

定西市| 罗甸县| 平陆县| 南平市| 连山| 邹城市| 临清市| 太仆寺旗| 宝鸡市| 南陵县| 施甸县| 承德市| 合山市| 安塞县| 台东市| 青浦区| 兴国县| 潞西市| 墨江| 丰原市| 科技| 建湖县| 绥中县| 鸡西市| 蛟河市| 彰化市| 隆昌县| 沙洋县| 丹江口市| 金山区| 望都县| 遵义市| 株洲市| 陈巴尔虎旗| 肇州县| 惠水县| 阳城县| 海阳市| 木里| 靖宇县| 潢川县|