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

Go Back   Android Development Forum - Basic4android > Basic4ppc (Windows Mobile) > Code Samples & Tips
Documentation Wiki Register Members List B4P Search Today's Posts Mark Forums Read

Code Samples & Tips Share your recent discoveries and ideas with other users.

saving and reading encrypted crypto files

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 04-07-2009, 12:39 AM
hlo's Avatar
hlo hlo is offline
Junior Member
 
Join Date: Feb 2009
Posts: 16
Default saving and reading encrypted crypto files

working on a medical database and needing to encrypt some data in it. used crypto but found I had trouble figuring out how to save a retrieve encrypted data. here is what i came up with. may not be the best way, but it works.

'Crypto is a Crypto object, Bit is a Bitwise object, Bin is a Binaryfile object
Sub Globals
Dim string(0) As Byte, secret(0) As Byte, s3(0) As Byte,string2(0) As Byte
s4=""
x=0
length=0
'used lots of variables so no chance of cross over of data for demo
PassPhrase = "password" 'not recomended - best to save password as an encrypted file to compare with what is typed in
txtString="begin- a text file to encrypt -end" 'just a file to encrypt than decrypt
End Sub

Sub App_Start
FileClose(c2) 'i always close my files 1st to be sure
FileClose(c1)
Bit.New1
Crypto.New1
encryptx 'encrypt and save routine
decryptx 're-read then decrypt routine
AppClose
End Sub

Sub Encryptx
string() = Bit.StringToBytes(txtString,0,StrLength(txtString) ) 'convert the string to bytes
secret() = Crypto.Encrypt(PassPhrase, string()) 'crypto routine
x=ArrayLen(secret()) 'get length of array to save
FileOpen(c1,"test.txt",cRandom)
bin.New1(c1,True)
bin.WriteInt16(x) 'save length of array
bin.WriteBytes(secret()) 'save encrypted data as bytes
FileClose(c1)
Msgbox("done encrypt")
End Sub

Sub decryptx
FileOpen(c2,"test.txt",cRandom)
bin.New1(c2,True)
x2=bin.ReadInt16 'read in array size
Dim s3(x2) As byte 'reset dim to proper size - believe it or not, this makes a difference
length = bin.ReadBytes(s3(), x2) 'read in string for x2 bytes - length variable not used
FileClose(c2)
string2()=crypto.Decrypt(PassPhrase,s3()) 'crypto routine
txtString=bit.BytesToString(string(),0,ArrayLen(st ring2())) 'turn back to string
Msgbox("decrypted file "&txtstring)
End Sub

hope it helps some one.
Attached Files
File Type: sbp aa_ed_test.sbp (1.8 KB, 62 views)
__________________
HLO, gst mobilesoft of Atlanta
http://gstmobilesoft.com
HTC8900 (ATT Tilt)and Moto Q9h
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
Need help understanding Crypto tsteward Questions (Windows Mobile) 1 09-15-2008 02:23 PM
Crypto error Raytracer Questions (Windows Mobile) 4 07-31-2008 12:39 PM
Crypto Error Raytracer Italian Forum 0 07-30-2008 04:39 PM
Reading binary files jgm Questions (Windows Mobile) 5 05-28-2008 11:09 AM
Crypto - Which algorithm is used? Nycran Questions (Windows Mobile) 12 12-09-2007 08:45 PM


All times are GMT. The time now is 04:39 AM.


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