Here are is an example for VB that demonstrates encryption from file to memory in a streaming fashion. It shows how to use the Rijndael algorithm.
Visual Basic |
Copy Code |
' This example encrypts data using the Rijndael method from a file to memory in 8K (8192 byte) chunks.
Const CHUNKSIZE = 8192
Dim xEncryptor As New XceedEncryption
Call xEncryptor.License( "your license key" )
Dim lOffSet As Long Dim lFileSize As Long Dim vaBytesRead As Variant Dim vaEncrypted As Variant
Set xEncryptor. EncryptionMethod = New XceedRijndaelEncryptionMethod
lOffSet = 0 ' We must track the current offset
On Error Resume Next
Call xEncryptor. EncryptionMethod.SetSecretKeyFromPassPhrase("This is a weak pass phrase!", 128)
lFileSize = FileLen("c:\temp\source.txt")
While lOffSet < lFileSize 'bEndOfData will be true if the current offset + CHUNKSIZE exceeds the end of the file.
vaEncrypted = xEncryptor.ReadFile("c:\temp\source.txt", lOffSet, CHUNKSIZE, efpEncrypt, _ (lOffSet + CHUNKSIZE >= lFileSize), vaBytesRead)
If Not IsEmpty(vaEncrypted) Then ' You now have a portion of encrypted data you can use. ' For example, transfer it, process it, etc. End If
lOffSet = lOffSet + vaBytesRead Wend
If Err.Number = 0 Then MsgBox "Finished encrypting file to memory." Else MsgBox Err.Number & " " & Err.Description End If |