|
Post by Kelly Ethridge on Nov 15, 2006 1:07:15 GMT -5
This is a probably the simplest way to encrypt a file. It is not the optimal way for large files, but can be expanded to accommodate them easily.
This example reads an entire file into a byte array, encrypts it, then writes the encrypted byte array out to a new file.
Dim pt() As Byte pt = File.ReadAllBytes("c:\somefile.txt") Dim csp As New RijndaelManaged ' Set the Key and IV here if prefered. Dim t As ICryptoTransform Set t = csp.CreateEncryptor Dim ct() As Byte ct = t.TransformFinalBlock(pt, 0, cArray.GetLength(pt)) File.WriteAllbytes "c:\somefile.txt.encrypted", ct
As you can see, there is no Key or IV set in this example. They are automatically generated when the csp.CreateEncryptor method is called. You should set your own Key and IV if needed, or use the generated ones after the encryption by retrieving them through the Key and IV properties of the csp object.
|
|