Quantcast
Channel: Xojo Programming Forum - Latest topics
Viewing all articles
Browse latest Browse all 4004

Encrypt/decrypt a .txt file

$
0
0

Dear all,
I would like to encrypt a .txt file and then including into the built App (in the Resources folder). For then be able to read (=decrypt) and use the information stored from within the App .
I tried to encrypt it using:

Var key As MemoryBlock = Crypto.GenerateRandomBytes(16)  
Var initVector As MemoryBlock = Crypto.GenerateRandomBytes(16) 
Var encrypted As MemoryBlock
encrypted = Crypto.AESEncrypt(key, theInputText, Crypto.BlockModes.CBC, initVector)

and then export this encrypted text into a new file. But when I ready this file in order to decrypt, using:
decrypted = Crypto.AESDecrypt(key, encrypted, Crypto.BlockModes.CBC, initVector)

I can recover the text but I loose the returns and tabs.

To read or write the file I use:

t = TextInputStream.Open(theFile)
t.Encoding = Encodings.UTF8

Any suggestion or working code (preferable using the new Crypto module in Xojo) I can use as a good starting point?
Thanks in advance.

L.

10 posts - 5 participants

Read full topic


Viewing all articles
Browse latest Browse all 4004

Trending Articles