当前位置:编程学习 > C#/ASP.NET >>

请教各位,能否将如下代码转换到c#

<?php
Class TripleDES {
public static function Encrypt($key,$text) {
$cipher = mcrypt_module_open(MCRYPT_3DES, '', MCRYPT_MODE_ECB, '');
srand((double)microtime() * 1000000);
$size=mcrypt_enc_get_iv_size($cipher);
$iv = mcrypt_create_iv($size, MCRYPT_RANDOM);
if(mcrypt_generic_init($cipher, $key, $iv) != -1){
$cipherText = mcrypt_generic($cipher,$text);
mcrypt_generic_deinit($cipher);
return bin2hex($cipherText);
}
}

public static function Decrypt($key,$encryptedText) {
$cipherText=self::Hex2bin($encryptedText);
$cipher = mcrypt_module_open(MCRYPT_3DES, '', MCRYPT_MODE_ECB, '');
srand((double)microtime() * 1000000);
$size=mcrypt_enc_get_iv_size($cipher);
$iv = mcrypt_create_iv($size, MCRYPT_RAND);
if (mcrypt_generic_init($cipher, $key, $iv) != -1){
$decrypted_data = mdecrypt_generic($cipher,$cipherText);
mcrypt_generic_deinit($cipher);
return $decrypted_data;
}
}
public static function Hex2bin($h) {
if(!is_string($h)) return null;
$r='';
for ($a=0; $a<strlen($h); $a+=2) {
$r.=chr(hexdec($h{$a}.$h{($a+1)}));
}
return $r;
}
}
/*
$key = "111111";
$message = "2222222";
$d = new TripleDES;
$ht = $d->Encrypt($key, $message);
$htd = $d->Decrypt($key, $ht);
echo $ht."------------------>".$htd."<hr />Standard->key:111111  str:2222222   output:C7375081D6C37A00";
*/
 ?>
--------------------编程问答-------------------- 参考 http://hi.baidu.com/11345/item/ae131a3f26dc41627c034b88 --------------------编程问答-------------------- 我对这个不是很了解,能帮我写个完整的例子么,谢谢 --------------------编程问答-------------------- 因为要匹配转换,所以比较麻烦
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,