HighTechTalks DotNet Forums  

DESCryptoServiceProvider

Dotnet Security microsoft.public.dotnet.security


Discuss DESCryptoServiceProvider in the Dotnet Security forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Ondrej Sevecek
 
Posts: n/a

Default DESCryptoServiceProvider - 03-02-2005 , 09:24 AM






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.



Reply With Quote
  #2  
Old   
Dominick Baier [DevelopMentor]
 
Posts: n/a

Default Re: DESCryptoServiceProvider - 03-02-2005 , 12:09 PM







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/PermaL...f-eb06ab317075

which uses RijndaelManaged and a FileStream. Should be easy to modify

Dominick Baier - DevelopMentor
www.leastprivilege.com

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.





Reply With Quote
  #3  
Old   
Valery Pryamikov
 
Posts: n/a

Default Re: DESCryptoServiceProvider - 03-04-2005 , 07:31 PM



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

"Ondrej Sevecek" <ondra_at_sevecek_dt_com> wrote

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.




Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.