File Encryption

96 views
Skip to first unread message

Unik

unread,
Jun 26, 2018, 11:51:38 PM6/26/18
to DroidScript
Hi,
Is it possible to encrypt files using droidscript...?
I want to make a app that encrypts file such as music,videos etc.

BareK

unread,
Jun 27, 2018, 3:36:37 AM6/27/18
to DroidScript
Hi :)

Here's what I found about it:
It does not seems to be possible at the moment.

The best you can do is reading any file in base64, which you can crypt easily (see the "Security Encryption" sample).
You can also easily write this encrypted base64 string reprensation of the file using app.WriteFile.
But all you'll have is a text file and a base64 string.

If you're able to work with base64 formats you're done (remember to add the format header before).
But you won't be able to re-create the original file and write it on the phone.

Other sources:

Netpower8

unread,
Jun 27, 2018, 4:06:53 AM6/27/18
to DroidScript
There is a method app.CreateCrypt(); you can encrypt files with this.

Unik

unread,
Jun 28, 2018, 5:19:22 AM6/28/18
to DroidScript
hi,
Netpower8, would you please kindly tell me, How can I encrypt file using app.CreateCrypt(); function...?

BareK

unread,
Jun 28, 2018, 6:02:51 AM6/28/18
to DroidScript
Unik I'm affraid that Netpower8 is talking about the same function as I did (you can find it in the "Security Encryption" sample from DroidScript's sample menu).
If this is the case it can only encrypt strings, so unfortunately my answer remains valid.
Correct me if I'm wrong.

Netpower8

unread,
Jun 28, 2018, 9:20:54 PM6/28/18
to DroidScript
you can ALSO encrypt other file type... it just need to do a bit of work....
 convert binary files into a string and then encrypt the string. this method will make your file bigger but the question posted was file encryption
so the answer is still valid =)


Netpower8

unread,
Jun 28, 2018, 9:50:48 PM6/28/18
to DroidScript
to be precise the binary file can be converted into a hex string data... use this hex string data for encryption.
on the other side just do the reverse to get the file back to its original form

Unik

unread,
Jun 30, 2018, 5:24:51 AM6/30/18
to DroidScript
yeah, It works...
I encrypted the file using this method and it worked smoothly for small size files below 1mb...
but it is not so reliable for large files...
so I decided to encrypt only the first 4 kb of file as it will be faster...
but I am unable to replace the first 4kb data of file with my encrypted data...
can you please help...?

fil = "/sdcard/index.html"

file = app.CreateFile( fil,"r" );

data = file.ReadData(4.875*1024,"hex");

file.Clos);

enc = crp.Encrypt (data );

now I get the encrypted data but how to insert it to the original file and replace its first 4kb data with encrypted data...?

Steve Garman

unread,
Jun 30, 2018, 5:49:13 AM6/30/18
to DroidScript
You can't put it back into the same file because the data is longer.

You'll need to create a new file and using the "rw" option of CreateFile, put the encrypted dats in it, then read the rest of the data from the old file and add it to the new one. Both writes will be best accomplished using WriteData.

If you manage that you will have a similarly interesting time reconstructing the file when you decrypt.

I wouldn't recommend this process but I don't know what you are trying to achieve. Is there some reason why you can't send the encrypted bit and the plsin binary as separate files?

Unik

unread,
Jul 10, 2018, 1:36:37 AM7/10/18
to DroidScript
I just want to corrupt or encrypt the file and make it unusable and again reverse the process and get the original file back like as vault...

I tried the aforementioned method, It works fine but if the file is more than 25mb it either stops responding or takes too much longer time...

I would like to ask if there is any other method to corrupt the file and again making it useable...

alex.symbroson

unread,
Jul 10, 2018, 4:12:06 AM7/10/18
to DroidScript
you could try splitting the source into parts ans write them partially into the file - but you'd have to detect these parts later for decrypting

ie


var src = "abcdef";
var dst = [];
const buflen = 3;

//encrypt
var encrypt = btoa;
for(var i=0; i<src.length; i+=buflen) {
dst.push(encrypt(src.slice(i, i+buflen)));
}
dst = dst.join(";");
alert(dst);

//decrypt
var decrypt = atob;
src = dst.split(";");
dst = src.map(decrypt).join("");
alert(dst);

Netpower8

unread,
Jul 10, 2018, 8:03:53 AM7/10/18
to DroidScript
Yes. I was going to suggest to split the file also.
Reply all
Reply to author
Forward
0 new messages