System.Security.Cryptography

 

None.gif         static   void  Main( string [] args)
ExpandedBlockStart.gifContractedBlock.gif        
dot.gif {
InBlock.gif            SymmetricAlgorithm provider 
= SymmetricAlgorithm.Create("TripleDES");
InBlock.gif            provider.Key 
= Encoding.Default.GetBytes("6HD+Ngi8JoGmDog=");
InBlock.gif            provider.IV 
= Encoding.Default.GetBytes("gi8joCmd");
InBlock.gif
InBlock.gif
InBlock.gif            ICryptoTransform encryptor 
= provider.CreateEncryptor();
InBlock.gif            
string clearData = "This is test";
InBlock.gif            Console.WriteLine(
"Clear Data:" + clearData);
InBlock.gif            Stream clearData1 
= new MemoryStream(Encoding.Default.GetBytes(clearData));
InBlock.gif            Stream encryptedData 
= new MemoryStream();
InBlock.gif
InBlock.gif            CryptoStream crypoStream 
= new CryptoStream(encryptedData, encryptor, CryptoStreamMode.Write);
InBlock.gif            
byte[] buffer = new byte[1024];
InBlock.gif            
int count = 0;
InBlock.gif
InBlock.gif            
while ((count = clearData1.Read(buffer, 01024)) > 0)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                crypoStream.Write(buffer, 
0, count);
ExpandedSubBlockEnd.gif            }

InBlock.gif
InBlock.gif            crypoStream.FlushFinalBlock();
InBlock.gif            encryptedData.Position 
= 0;
InBlock.gif            
byte[] encryptedDataArray = new Byte[encryptedData.Length];
InBlock.gif            encryptedData.Read(encryptedDataArray, 
0, encryptedDataArray.Length);
InBlock.gif            Console.WriteLine(
"Encrypted data:"+Encoding.Default.GetString(encryptedDataArray ));
InBlock.gif            Console.ReadLine();
ExpandedBlockEnd.gif        }
posted on 2006-09-29 10:16 吴勇 阅读( ...) 评论( ...) 编辑 收藏

转载于:https://www.cnblogs.com/wuyong/archive/2006/09/29/517915.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值