Write Text Data to a Binary file (Also read it back)
Hey all.
Ii have an app that uses an array to hold text data (many reasons for this, but it is the way it is).
In any case, I encrypt the data using an AES_Rijndael Block Cipher, all is well.
I would now like to write this data to a BINARY file (I cannot do so to a text file as part of the encrypted data may contain the vbCRLF char set).
Ii need to also be able to read thebinary data back into my app, then populate an array with the DECRYPTED data (I have the encryption and decryption routines already working).
How can one do this?
Thanks.
Re: Write Text Data to a Binary file (Also read it back)
VB Code:
'to write to file
dim x as long
open myfile for binary access write as #1
for x=1 to len(myencodedstring)
put #1,x,mid(myencodedstring,x,1)
next x
close #1
'to read from file
dim x as long
open myfile for binary access read as #1
x=1
myencodedstring=""
do while not eof(1)
get #1,x,mychar
myencodedstring=myencodedstring & mychar
x=x+1
loop
close #1
Re: Write Text Data to a Binary file (Also read it back)
Thanks mebhas, I understand exactly what you have coded and in fact that was my thought. However, how do I determine the NEXT array element? For example,
Array1(bob),
Array2(ted),
Array3(carol),
Array4(alice)
Now EACH element gets encrypted (ex araray1(#*u0^b5%4#). I need to write each array element data to a file, then do the next array element. So, I guess my question is how do I determine the END of an element when reading the file so I can populate the NEXT element.
Keep in mind that an element (once encrypted) may contain the vbCRLF pair of [dec: 13,10] or [hex:d,a], so I cannot check for vbCRLF (tried this but the data read in is irradic).
Thanks.
G.
RESOLVED -> Re: Write Text Data to a Binary file (Also read it back)
Thanks to all, but I figured it out. Used UBOUND and wrote the enitre array to disk by doing this:
CLng(UBound(ctrlArray)) then wrote this to dis, then the array. I then read th UPPERBOUNDS value from disk, redimed the array and read it it.
All is wel..
G