Re: DESCryptoServiceProvider

From: Valery Pryamikov (valery_at_harper.no)
Date: 03/05/05


Date: Sat, 5 Mar 2005 01:31:50 +0100

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 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.
>
>



Relevant Pages