Encrypt file with WriteEncryptedObject

susu

Well-Known Member
Licensed User
Longtime User
I'm trying to encrypt a file with WriteEncryptedObject, my code is:

B4X:
Dim output, input As RandomAccessFile

input.Initialize(File.DirRootExternal, "normal.txt", True)
output.Initialize(File.DirRootExternal, "secret.dat", False)

output.WriteEncryptedObject(input, "some secret password", output.CurrentPosition)

input.Close
output.Close

It create "secret.dat" but the file size is only 37 bytes.
I know something wrong but I can't figure out :sign0104:
 

susu

Well-Known Member
Licensed User
Longtime User
Thank you Erel. What if the file is not text (jpeg, png...) ?
 
Upvote 0

susu

Well-Known Member
Licensed User
Longtime User
Thank you Erel. Now I can encrypt/decrypt a jpg file but the speed is really slow. It takes about 7 seconds to decrypt a 130KB file on dual-core CPU device. My code below:

B4X:
Dim input As RandomAccessFile
Dim Buffer() As Byte
input.Initialize(File.DirRootExternal, "encrypted.dat", True)
Buffer = input.ReadEncryptedObject("password", input.CurrentPosition)
   
Dim InputStream1 As InputStream
InputStream1.InitializeFromBytesArray(Buffer, 0, Buffer.Length)
   
InputStream1.Close
input.Close
   
Dim bm As Bitmap
bm.Initialize2(InputStream1)
   
Activity.SetBackgroundImage(bm)

Do you have any idea to speed up? Thank you.
 
Upvote 0

susu

Well-Known Member
Licensed User
Longtime User
Here my project, please take a look. Thank you :D
 
Upvote 0

susu

Well-Known Member
Licensed User
Longtime User
Thank you Erel. How about this idea:
Add 10 random bytes into the beginning of jpg file. When loading, just read the content after first 10 bytes. My purpose is make it a bit harder to read these jpg files. Is it possible?
 
Upvote 0

susu

Well-Known Member
Licensed User
Longtime User
I tried to write 56 bytes into jpeg file then save as a new file => It's OK.
But I got problem when read it again. Please take a look at attached file. Thank you Erel.
 
Upvote 0
Top