码迷,mamicode.com
首页 > 其他好文 > 详细

测试openssl_encrypt

时间:2017-09-21 19:29:53      阅读:373      评论:0      收藏:0      [点我收藏+]

标签:reac   log   ons   int   like   raw   foreach   byte   -128   

<?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

标签:reac   log   ons   int   like   raw   foreach   byte   -128   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!