Basic4ppc - Windows Mobile Development  

Go Back   Basic4ppc - Windows Mobile Development > Main Category > Questions & Help Needed
Home Register FAQ Members List Search Today's Posts Mark Forums Read

Questions & Help Needed Post any question regarding Basic4ppc.


encrypt in1st app, decrypt in 2nd app


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 06-01-2008, 01:43 PM
Junior Member
 
Join Date: May 2007
Posts: 16
Default encrypt in1st app, decrypt in 2nd app

Hi all,

in the 1st application a textbox must be filled with a nickname
this nickname is encrypted and stored in a .csv file, no problem with this part.

in the 2nd application the .csv file is loaded in a table. The encrypted nickname must be decrypted but i get an error that the arraylen(secret()) is 0 (zero)
Code:
Sub Globals '1st app
    'Declare the global variables here.
..
..
bit.New1
crypto.New1
Dim string(0) As Byte, secret(0) As Byte 
PassPhrase = "schoen" 
..
End Sub

Sub Encrypt_Save
..
string() = Bit.StringToBytes(Nickname,0,StrLength(Nickname)) 'Convert the string to an array of bytes.
    secret() = Crypto.Encrypt(PassPhrase, string()) 'Save the encrypted data.
    For i = 0 To ArrayLen(secret())-1 'Show the encrypted data in the TextBox
        s = s & bit.DecToHex(secret(i))
    Next
    Nickname = s
s = ""
..

end sub


Sub Globals  '2nd application
    'Declare the global variables here.
..
..
Dim string(0) As Byte
Dim secret(0) As Byte 
Crypto.New1
Bit.New1
PassPhrase = "schoen"
..
End Sub

Sub Decrypt
..
Nickname = TabelDeelnemers.Cell("Nickname",2)
..
secret() = Nickname
..
If ArrayLen(secret()) = 0 Then Return
    string() = Crypto.Decrypt(PassPhrase,secret()) 'Decrypt the data.
    Nickname_Decrypted = Bit.BytesToString(string(),0,ArrayLen(string())) 'Convert the array to a string.
..
End sub
I assume the variable secret() must be set to Nickname, but i get the mentioned error. Other ways to set the secret() var. is unknown to me. I hope that someone
in this forum can help.

thanks in advance

Arrie
Reply With Quote
  #2 (permalink)  
Old 06-01-2008, 03:16 PM
Erel's Avatar
Administrator
 
Join Date: Apr 2007
Posts: 3,199
Default

Secret is an array of bytes, so you can't directly assign a string to secret.
You need to again use Secret() = Bit.StringToBytes(...)
Reply With Quote
  #3 (permalink)  
Old 06-01-2008, 04:40 PM
Junior Member
 
Join Date: May 2007
Posts: 16
Default

i'm using now :

Secret() = Bit.BytesToString(Nickname,0,ArrayLen(Nickname))
string() = Crypto.Decrypt(PassPhrase,Secret()) 'Decrypt the data.
Nickname_2 = Bit.BytesToString(string(),0,ArrayLen(string())) 'Convert the array to a string.

But still an error (in dutch) "de objectverwijzing is niet op een exemplaar van een object ingesteld", (in english it must be something like this) "The objectreference is not on a valid object"
Reply With Quote
  #4 (permalink)  
Old 06-01-2008, 04:44 PM
Erel's Avatar
Administrator
 
Join Date: Apr 2007
Posts: 3,199
Default

Did you add a reference to the Bitwise library?
Did you add a Bitwise object named Bit?
Reply With Quote
  #5 (permalink)  
Old 06-01-2008, 04:47 PM
Junior Member
 
Join Date: May 2007
Posts: 16
Default

Yes for both
Bit.new1 is in sub Globals
Bitwise.dll only for desktop (it's a desktop app)
Reply With Quote
  #6 (permalink)  
Old 06-01-2008, 05:08 PM
Erel's Avatar
Administrator
 
Join Date: Apr 2007
Posts: 3,199
Default

It is not recommended to put Bit.New1 in Sub Globals.
Can you upload your code?
Reply With Quote
  #7 (permalink)  
Old 06-01-2008, 05:33 PM
Junior Member
 
Join Date: May 2007
Posts: 16
Default

Oke,

Uploaded, "Deelnemers.txt" must be renamed to "Deelnemers.csv" in this file is the encrypted data stored from the 1st application (as seen is the original post)

Arrie
Attached Files
File Type: sbp DecryptProbleem.sbp (2.0 KB, 7 views)
File Type: txt Deelnemers.txt (4.2 KB, 5 views)
Reply With Quote
  #8 (permalink)  
Old 06-01-2008, 06:56 PM
agraham's Avatar
Basic4ppc Expert
 
Join Date: Jul 2007
Location: Cheshire, UK
Posts: 1,770
Awards Showcase
Beta Tester Forum Contributer 
Total Awards: 2
Default

Try this
Code:
	Dim Secret(StrLength(Nickname)/2) As byte
	For i = 0 To ArrayLen(Secret()) - 1
		Secret(i) = Bit.HexToDec(SubString(Nickname, i*2, 2))
	Next
test1 doesn't show up in your listbox
test2 decodes as "w"
test3 decodes as "e"
test4 decodes as "Arjan"
test5 fails on bad data
Reply With Quote
  #9 (permalink)  
Old 06-01-2008, 08:59 PM
Junior Member
 
Join Date: May 2007
Posts: 16
Default

Agraham,

Thanks, but all decrypted data i see is complete fluffy stuff. I've copied your lines of code, but still no solution.

Thanks anyway

Arrie
Reply With Quote
  #10 (permalink)  
Old 06-01-2008, 09:29 PM
agraham's Avatar
Basic4ppc Expert
 
Join Date: Jul 2007
Location: Cheshire, UK
Posts: 1,770
Awards Showcase
Beta Tester Forum Contributer 
Total Awards: 2
Default

Were those decryptions that I gave correct or not? They looked like they might be, especially test4 with an inital capital letter and what seems a sensible name. What are you doing that is different
Code:
Sub Button29_Click 'Printen gegevens deelnemers
Naam = Listbox38.Item(Listbox38.SelectedIndex)
Aantal = TabelDeelnemers.RowCount
For Teller = 1 To Aantal -1
	If TabelDeelnemers.Cell("naam", Teller) = Naam Then
   		Nickname = TabelDeelnemers.Cell("Bijnaam",Teller)  'Bijnaam is dutch for Nickname
   	End If
Next
	Dim Secret(StrLength(Nickname)/2) As byte
	For i = 0 To ArrayLen(Secret()) - 1
		Secret(i) = Bit.HexToDec(SubString(Nickname, i*2, 2))
	Next
	string() = Crypto.Decrypt(PassPhrase,secret()) 'Decrypt the data.
	Nickname_2 = Bit.BytesToString(string(),0,ArrayLen(string())) 'Convert the array to a string.
Msgbox(Nickname_2)
End Sub
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 On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Decrypt Big JR Questions & Help Needed 8 06-30-2007 08:36 PM
Trying to encrypt a file transer mwaite Questions & Help Needed 8 06-05-2007 06:02 PM
Encrypt / Decrypt a complete file Erel Code Samples & Tips 3 06-05-2007 05:20 PM


All times are GMT. The time now is 02:12 AM.


Powered by vBulletin® Version 3.6.12
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.1.0