数据加密的问题!

emmajiang 2006-04-18 08:53:32
在VC.net中可不可以用SymmetricAlgorithm 类,如果可以的话要加什么头文件或别的,又如何对所要加密的数据加密呢,学习中,请各位大虾请教!谢谢!
...全文
176 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
emmajiang 2006-04-22
  • 打赏
  • 举报
回复
在C#中是这样的,但是C++中呢?
紫焰月读 2006-04-22
  • 打赏
  • 举报
回复
应该是一样的
using System::Security::Cryptography;
下面是MSDN抄的一个列子可以参考
void EncryptData( String^ inName, String^ outName, array<Byte>^rijnKey, array<Byte>^rijnIV )
{

//Create the file streams to handle the input and output files.
FileStream^ fin = gcnew FileStream( inName,FileMode::Open,FileAccess::Read );
FileStream^ fout = gcnew FileStream( outName,FileMode::OpenOrCreate,FileAccess::Write );
fout->SetLength( 0 );

//Create variables to help with read and write.
array<Byte>^bin = gcnew array<Byte>(100);
long rdlen = 0; //This is the total number of bytes written.

long totlen = (long)fin->Length; //This is the total length of the input file.

int len; //This is the number of bytes to be written at a time.

SymmetricAlgorithm^ rijn = SymmetricAlgorithm::Create(); //Creates the default implementation, which is RijndaelManaged.

CryptoStream^ encStream = gcnew CryptoStream( fout,rijn->CreateEncryptor( rijnKey, rijnIV ),CryptoStreamMode::Write );
Console::WriteLine( "Encrypting..." );

//Read from the input file, then encrypt and write to the output file.
while ( rdlen < totlen )
{
len = fin->Read( bin, 0, 100 );
encStream->Write( bin, 0, len );
rdlen = rdlen + len;
Console::WriteLine( "{0} bytes processed", rdlen );
}

encStream->Close();
fout->Close();
fin->Close();
}
louieDarkCrystal 2006-04-21
  • 打赏
  • 举报
回复
System.Security.Cryptography.SymmetricAlgorithm 命名空间
自己再看看吧,可能有改变了和原来比
装一个动态帮助吧 ,比较方便

7,540

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 VC.NET
社区管理员
  • VC.NET社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧