首页 > 其他 > 详细

测试openssl_encrypt

时间:2017-09-21 19:02:17      阅读:269      评论:0      收藏:0      [点我收藏+]
<?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 = "234wsdfs@#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

原文:http://www.cnblogs.com/php-linux/p/7569962.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!