I need to load a file into a varible type System.IO.Stream and then decrypt it (or decrypt it and then load it into a stream). I need to know whats the best encryption for the job. Baiscly I dont want to store the file on the users hard drive.
Any one have any source or links that could help? Is this even possible?
Dim fsRead As New FileStream("c:\pic.jpg", FileMode.Open)
Dim msEncrypted As New MemoryStream(fsRead.Length)
Dim msPlain As MemoryStream
Dim brRead As New BinaryReader(fsRead)
Dim bytesRead As Byte() = brRead.ReadBytes(fsRead.Length)
msEncrypted.Write(bytesRead, 0, fsRead.Length)
Dim x As New Crypto("password")
msPlain = x.DecryptStream(msEncrypted)
'write to fswrite
Dim fsWrite As New FileStream("c:\orignalfile.jpg", FileMode.Create, FileAccess.Write)
Dim decryptedFile() As Byte
decryptedFile = msEncrypted.ToArray
Dim I As Long
For I = 0 To UBound(decryptedFile)
fsWrite.WriteByte(decryptedFile(I))
Next
fsWrite.Close()
fsRead.Close()
msPlain.Close()
msEncrypted.Close()
brRead.Close()
End Sub
Private Sub EncFile()
Dim fsRead As New FileStream("c:\test.jpg", FileMode.Open)
Dim msPlain As New MemoryStream(fsRead.Length)
Dim msEncrypted As MemoryStream
Dim brRead As New BinaryReader(fsRead)
'Read File into msPlain
Dim bytesRead As Byte() = brRead.ReadBytes(fsRead.Length)
msPlain.Write(bytesRead, 0, fsRead.Length)
'Encrypt msPlain
Dim x As New Crypto("password")
msEncrypted = x.EncryptStream(msPlain)
'Write to fsWrite somehow
Dim fsWrite As New FileStream("c:\streamout.jpg", FileMode.Create, FileAccess.Write)
Dim EncryptedFile() As Byte
EncryptedFile = msEncrypted.ToArray
Dim I As Long
For I = 0 To UBound(EncryptedFile)
fsWrite.WriteByte(EncryptedFile(I))
Next
fsWrite.Close()
fsRead.Close()
msPlain.Close()
msEncrypted.Close()
brRead.Close()
End Sub
was having trouble with decrypting the streams so I wrote this to test and the decryption function (in the class) is not working (i think) anyone know whats wrong?
I dont know whether there was some thing wrong with the code you gave me or I changed it by accident but I figured it out and got it working propertly. Now im gonna strip the code down and throw it into a class.