PHP 教程:PHP 和.net 中 des 加解密
PHP 和.net 中 des 加解密的实现方法,需要的朋友可以参考一下
php5.x 版本,要添加 php 扩展 php_mcrypt。
PHP 版:
代码如下:
class
STD3Des
{
private
$key
= "";
private
$iv
= "";
/**
* 构造,传递二个已经进行 base64_encode 的 KEY 与 IV
*
* @param string $key
* @param string $iv
*/
function
__construct (
$key
,
$iv
)
{
if
(
empty
(
$key
) ||
empty
(
$iv
)) {
echo
'key and iv is not valid';
exit
();
}
$this
->key =
$key
;
$this
->iv =
$iv
;
}
/**
*加密
* @param <type> $value
* @return <type>
*/
public
function
encrypt (
$value
)
{
$td
= mcrypt_module_open(MCRYPT_3DES, '', MCRYPT_MODE_CBC, '');
$iv
=
base64_decode
(
$this
->iv);