DESCryptoProvider

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,


How can I use the DES Crypto Provider to take in a string and encrypt that
with a key then return an encrypted string and vica versa? All the examples
I have seen are based on files and streams.

Thanks.
 
If you use the CreateEncryptor/CreateDecryptor method, you will get an
object that implements ICryptoTransform. From there, you can use the
TransformBlock and TransformLastBlock methods directly (you must always use
TransformLastBlock when you pass in the last block of data, as padding is
often involved). Most block ciphers (like DES) support encrypting/decrypting
multiple blocks at a time, so you can actually pass in the entire "string".
I quoted string, becuse the method actually deals with byte arrays instead
of strings.
The CryptoStream is simply a mechanism that simplifies the process of moving
that byte data to a stream.

-Rob Teixeira [MVP]
 
Back
Top