Download the free trial version
Basic4android Video
Features
Tutorials and manuals
Showcase
Screenshots

Go Back   Android Development Forum - Basic4android > Basic4android > Basic4android Getting started & Tutorials
Documentation Wiki Register Members List B4P Search Today's Posts Mark Forums Read

Basic4android Getting started & Tutorials Android development starts here. Please do not post questions in this sub-forum.

Encrypting information with RandomAccessFile library

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 09-18-2011, 01:34 PM
Erel's Avatar
Administrator
 
Join Date: Apr 2007
Posts: 15,689
Awards Showcase
Basic4ppc Founder 
Total Awards: 1
Default Encrypting information with RandomAccessFile library

RandomAccessFile v1.30 introduces two new methods named: WriteEncryptedObject and ReadEncryptedObject.
These methods are similar to WriteObject and ReadObject methods. The difference is that the new methods encrypt the object before writing it to a file and decrypt it before reading. The encryption algorithm is AES-256 which is considered to provide strong protection.

Android SQLite implementation doesn't support encryption. In many cases you can use these two methods instead. You can create a large Map or List with your own structures and save them to a file.
Edit: Using the new SQLCipher library you can encrypt SQLite databases: http://www.basic4ppc.com/forum/basic...r-library.html

Developers who are not familiar with WriteObject / ReadObject should try these methods. They are very easy to use and allow you to store complicated objects in a single line of code. Unlike File.WriteMap / WriteList which convert the data to a string, WriteObject and WriteEncryptedObject can write many types of data without losing any information.

You can see more information about the supported types here: Basic4android - RandomAccessFile

Example of writing an encrypted List to a file:
Code:
Sub Activity_Create(FirstTime As Boolean)
    
Dim list1 As List
    list1.Initialize
    
For i = 1 To 1000
        list1.Add(
"Item #" & i)
    
Next
    
'writing the object
    Dim raf As RandomAccessFile
    raf.Initialize(
File.DirRootExternal, "1.dat"False)
    raf.WriteEncryptedObject(list1, 
"some secret password", raf.CurrentPosition)
    
'you can continue to write more objects to this file
    '...
    raf.Close
    
    
'reading the object
    Dim raf As RandomAccessFile
    raf.Initialize(
File.DirRootExternal, "1.dat"False)
    
Dim list2 As List
    list2 = raf.ReadEncryptedObject(
"some secret password", raf.CurrentPosition)
    
Log(list2)
    raf.Close
End Sub
Other more advanced encryption methods are available in the encryption library: http://www.basic4ppc.com/forum/addit...n-library.html

The library is available here: http://www.basic4ppc.com/forum/addit...redobject.html
Reply With Quote
  #2 (permalink)  
Old 11-02-2011, 01:18 PM
AscySoft's Avatar
Knows the basics
 
Join Date: Jul 2011
Posts: 96
Question

Right now I am working on exporting to some text files...

I use encryption method describe by you, above using WriteEncryptedObject.

The text files are OK, but the question is..
How do I decrypt them on Windows PC? (There I use net framework 2.0 application)
Could you enlighten me? Thanks, I know is not B4A, but is related anyway
__________________
for me, English is a foreign language, so be patient
Reply With Quote
  #3 (permalink)  
Old 11-03-2011, 09:55 AM
Erel's Avatar
Administrator
 
Join Date: Apr 2007
Posts: 15,689
Awards Showcase
Basic4ppc Founder 
Total Awards: 1
Default

You will not be able to use a file written with WriteEncryptedObject on the PC. You will need to encrypt the data yourself with the Encryption library.
Reply With Quote
  #4 (permalink)  
Old 11-03-2011, 10:18 AM
AscySoft's Avatar
Knows the basics
 
Join Date: Jul 2011
Posts: 96
Default

Quote:
Originally Posted by Erel View Post
You will not be able to use a file written with WriteEncryptedObject on the PC. You will need to encrypt the data yourself with the Encryption library.
Thanks, I'm working on that.
__________________
for me, English is a foreign language, so be patient
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
FilesEx library - returns file information agraham Additional Libraries 21 03-30-2011 12:29 PM
PowerStatus library giving battery information agraham Additional Libraries 0 05-29-2010 01:28 PM
Encrypting over Network Zenerdiode Questions (Windows Mobile) 5 11-08-2009 05:57 PM
Encrypting with TLS in Windows CE mikemike570 Questions (Windows Mobile) 2 03-16-2009 04:15 PM
Encrypting and Decrypting XerVision Questions (Windows Mobile) 1 06-16-2007 04:42 PM


All times are GMT. The time now is 10:00 AM.


Powered by vBulletin® Version 3.6.12
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0