encrypting/decrypting in win32

iI have a pretty large textfile (13MB) that I need to encrypt before adding it to a project of mine. Then, launching the app, the file gets decrypted.
For Mac, I decrypt it using the following shell, where f and g refer to the encrypted and decrypted files.

dim s as new Shell
s.Execute “openssl enc -aes-256-cbc -d -in " + f.ShellPath + " -out " + g.ShellPath + " -pass pass:” + DecodeBase64(“myPassword”)

For win32 builts, it seems the above shell does nothing, unless the PC has openssl installed; but I would avoid distributing an app that asks the user to install something more in order to work.

I made a test using an encrypted database, but unfortunatelly InnoSetup leaves the database-file at 13 MB, while a text file gets nicely compressed, reducing the size of the app.exe from 30MB to 19MB.
As for using encodeBase64, it is too simple to be decoded by everybody (something I would avoid for copyright reasons).

So, how to proceed to encrypt/decrypt (win32 builts only) such large file without the user being compelled to install third party components?
Being the app a freeware, I would appreciate suggestions not requiring deployment of plugins at additional cost.

BTW: searching the forum I could not find an answer to my question, unless I overlooked something.


maybe this blog post is helpful:


I tried it just now, but running it in the IDE I get two errors at the last two lines of the snippet (below), reporting:
Not enough arguments: missing memoryblock value for parameter “publicKey”
PEMPublic = encodePEMPublicKey(pub)


Not enough arguments: missing memoryblock value for parameter “publicKey”
PEMPrivate = encodePEMPublicKey(priv)

Dim priv,pub as String
// Generate a key pair in Xojo
if Crypto.RSAGenerateKeyPair(1024,priv,pub) then

// Now that we have the keys, convert them to PEM.
// These versions could be used elsewhere, like in PHP or another language.
dim PEMPublic, PEMPrivate as string
PEMPublic = EncodePEMPublicKey(pub)// code stumbles here and at following line
PEMPrivate = EncodePEMPrivateKey(priv)


So I tried the second Crypto example located in the Example Projects, but when I try to pass my 13MB string as message, I get an error saying that the size is too big. I guess I’m messing up things. Any idea how to proceed?

If you are interested in using RC4, we’ve got a version built in purely Xojo-code here, and it’s reasonably fast: https://forum.xojo.com/conversation/post/110903

Michael, I tried your rc4v6: it does perfectly for “latin” text.
But it seems rc4 doesnt like unicode-font based text (text in Bengali using unicode Bangla fonts), since the textArea gets full of unprintable chars. Really a pity.

dim s as String = rc4v6(mBangla, “CarloRb”)
TextArea1.SelText = rc4v6(s,“CarloRb”)//unprintable characters with Bangla text, but OK with latin text

really that probably should use MEMORYBLOCKS not STRINGS since its not textual data you get back from RC4

what you get isn’t “Bengali” text - its a bunch of bytes so trying to show it as “text” is pointless

Michael, this works OK, although it gets slower because of the decodeHex (for a 13 MB file I force-quitted after 3 minutes):

s is a property
s = rc4v6(encodeHex(mBangla), “CarloRb”)

TextArea1.SelText = decodeHex(rc4v6(s,“CarloRb”))

As Norman says, this is probably an Encoding issue.

You’ll need to remember the string encoding and set it, e.g.

dim s as string = rc4v6("data to encode", "encryptionKey")
// s now contains encoded bytes
dim t as string = rcv46(s, "encryptionKey")
// t now contains the original text, BUT we don't know what encoding it is
t = t.DefineEncoding(Encodings.UTF8)  // or whatever the actual encoding is

Done, and working fine. Thanks.
So I created the encrypted file and dropped it into my project: unfortunatelly compression (lzima or zip) leaves the size of the file to its original 12MB, as it happened with the encrypted database file. Bad luck.

[quote=197564:@Carlo Rubini]Done, and working fine. Thanks.
So I created the encrypted file and dropped it into my project: unfortunatelly compression (lzima or zip) leaves the size of the file to its original 12MB, as it happened with the encrypted database file. Bad luck.[/quote]

That’s to be expected: properly encrypted data looks like random data which is not amenable to compression.

You could, instead, Zip the data first, THEN encrypt it. That should reduce the size.

Yes, this is what I did using gzip/gunzip from macoslib, but it works OK for Mac while it raises an exception on win32 (something like classexception).

Using the following code win32 does not complain (although I know that the function is n ot recommended).
Dim s1 As String
Dim GzipString As new _GzipString
s1 = DefineEncoding(GzippedString.Decompress(s),encodings.UTF8)

ZIP files begin with the two characters PK

Try this:
Zip your file.
The change the first two bytes to 2 other random characters (now it doesn’t look like a zip file any more)

You could stop there because the data will not look to be easily recoverable by anything:
(unless you KNOW it is a zip file and that only the first two bytes are changed, the casual viewer will have a lot of trouble working out what the original was.)

If you want further obfuscation, you could then use encodebase64 , but that will increase the size.

And to get the data back, change the characters to PK, unzip the file, then delete the zip file to hide the evidence.

Actually I had thought of doing something like that, replacing the first 2 characters of the file (it seems gzipped files start by xú), but later I decided to use encryption. The temptation is still there thou.

Zip will reduce the size of your file ; encryption will not.

We are speaking about encrypting or modifying the first 2 bytes of an already compressed file.

You are missing the point.