|
security
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
DESCryptoServiceProviderHello,
would you please provide me with some simple sample of how to use the DESCryptoServiceProvider to encrypt a buffer byte[] buffer; with key byte[] key; I saw some sample using Streams, but is there a simpler method working for buffers? O. Hello Ondrej Sevecek" ondra_at_sevecek_dt_com,
you have to use CryptoStream. You could couple it with a MemoryStream to do it all in-Memory buffer based. if have an example here http://www.leastprivilege.com/PermaLink.aspx?guid=f73ca1e0-bcfa-4563-862f-eb06ab317075 which uses RijndaelManaged and a FileStream. Should be easy to modify Dominick Baier - DevelopMentor www.leastprivilege.com Show quoteHide quote > Hello, > > would you please provide me with some simple sample of how to use the > DESCryptoServiceProvider to encrypt a buffer > > byte[] buffer; > > with key > > byte[] key; > > I saw some sample using Streams, but is there a simpler method working > for buffers? > > O. > Working with buffers... something like following shall do it (not sure if it
simplier :-): SymmetricAlgorithm algorithm = DES.Create(); ICryptoTransform encryptor = algorithm.CreateEncryptor(); int blockByteSize = algorithm.BlockSize / 8; int nBlocks = ((data.Length+blockByteSize-1)/blockByteSize); Byte[] encryptedData = new Byte[nBlocks*blockByteSize]; for (int i = 0; i < nBlocks; i++) { if (i == nBlocks - 1) { Byte[] lastBlock = encryptor.TransformFinalBlock(data, i * blockByteSize, nBlocks * blockByteSize - data.Length); Array.Copy(lastBlock, 0, encryptedData, i * blockByteSize, lastBlock.Length); } else { encryptor.TransformBlock( data, i * blockByteSize, blockByteSize, encryptedData, i * blockByteSize); } } -Valery http://www.harper.no/valery Show quoteHide quote "Ondrej Sevecek" <ondra_at_sevecek_dt_com> wrote in message news:%23V6zZLzHFHA.896@TK2MSFTNGP10.phx.gbl... > Hello, > > would you please provide me with some simple sample of how to use the > DESCryptoServiceProvider to encrypt a buffer > > byte[] buffer; > > with key > > byte[] key; > > I saw some sample using Streams, but is there a simpler method working for > buffers? > > O. > >
Medium Level Trust and Reflection
API to access loaded assembly hash Method SetThreadPrincipal Active Directory Machine Account Permissions Make Security to Directory Authentication/Impersonation Inconsistency Assymetric Encryption - Interorperability between Java2, .NET and Openssl Forms authentication periodically requires re-login XmlSerialization of classes with declarative Security Windows user controls in a web page: Security |
|||||||||||||||||||||||