测试openssl_encrypt
Posted brady-wang
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了测试openssl_encrypt相关的知识,希望对你有一定的参考价值。
<?php //$string = ‘It works ? Or not it works ?‘; //$pass = ‘1234‘; //$method = ‘aes128‘; // // // //$a = openssl_get_cipher_methods(); //print_r($a); //foreach($a as $v) { // $res = openssl_encrypt($string,$v,$pass,OPENSSL_RAW_DATA,"dddddddd33333335"); // var_dump($res); // echo "<br>"; //} ?> <?php //$key should have been previously generated in a cryptographically safe way, like openssl_random_pseudo_bytes $plaintext = "234223423"; $cipher = "aes-128-cbc"; $key = "[email protected]#234"; $tag = "sdwewew"; if (in_array($cipher, openssl_get_cipher_methods())) { $ivlen = openssl_cipher_iv_length($cipher); $iv = "0000000000000000"; $ciphertext = openssl_encrypt($plaintext, $cipher, $key, $options=0, $iv); //store $cipher, $iv, and $tag for decryption later $original_plaintext = openssl_decrypt($ciphertext, $cipher, $key, $options=0, $iv); echo $original_plaintext."\n"; } ?>
以上是关于测试openssl_encrypt的主要内容,如果未能解决你的问题,请参考以下文章
如何使 openssl_encrypt 将输入填充到所需的块大小?
在 PHP 中将 mcrypt_encrypt 转换为 openssl_encrypt