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
  #11 (permalink)  
Old 06-01-2008, 10:00 PM
Junior Member
 
Join Date: May 2007
Posts: 16
Default

Hi Agraham,

The answers you gave were correct. Especially test4 (my name is Arjan). But when i create a new nickname in the first application, then there will be an error "CryptDecrypt failed at adress 0x8009005"

It appears when the original stringlength<6 everything works fine, but when it is 6 or more the abovementioned errormessage is shown.

Arrie
Reply With Quote
  #12 (permalink)  
Old 06-02-2008, 09:05 AM
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

Quote:
Originally Posted by Arrie View Post
It appears when the original stringlength<6 everything works fine, but when it is 6 or more the abovementioned errormessage is shown.
That must be something in your code. Are you truncating the encrypted string somehow? If you download the Crypto example from here Basic4ppc - Windows Mobile programming and Pocket PC Development (use only the source file together with the latest libraries from the Basic4ppc Desktop\Libraries folder) and replace the key with your key it not only produces the samre results as your tests but aalso deals OK with strings longer than 6.
Reply With Quote
  #13 (permalink)  
Old 06-02-2008, 10:18 AM
Junior Member
 
Join Date: May 2007
Posts: 16
Default

Hi Agraham,

I'm not aware that the data is truncated. can you decrypt this string "a498a0f2283376354b96f58f3b5473f4", when the result is what i expect, the data is ok. The original line (before encryption ) is 9 digits.

Thanks,

Arrie
Reply With Quote
  #14 (permalink)  
Old 06-02-2008, 10:34 AM
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

No, that fails with a bad data error. What was the original data?
Reply With Quote
  #15 (permalink)  
Old 06-02-2008, 10:46 AM
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

The problem is with DecToHex, it doesn't always return two characters so the data is being truncated. You need something like this.

Code:
For i = 0 To ArrayLen(secret())-1
  If secret(i)< 16 Then s = s & "0"
  s = s & bit.DecToHex(secret(i))
Next
EDIT:- Typo in the code above corrected, was 15 now 16

Last edited by agraham : 06-02-2008 at 01:55 PM.
Reply With Quote
  #16 (permalink)  
Old 06-02-2008, 10:54 AM
Junior Member
 
Join Date: May 2007
Posts: 16
Default

agraham @ 9:34 Original was Basic4PPC
Reply With Quote
  #17 (permalink)  
Old 06-02-2008, 07:15 PM
Junior Member
 
Join Date: May 2007
Posts: 16
Default

Oke Agraham,

So if i understood it correct, in the encryption of the data (in the 1st application) the truncade took place, and in the decryption of the data (in the 2nd application, we must use a prefix zero if the secret datapacket is smaller then 16(dec) or F(hex), is this correct ? And if so is this than a bug or just stupid programming from me

Greetings Arrie
Reply With Quote
  #18 (permalink)  
Old 06-02-2008, 07:26 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

Quote:
Originally Posted by Arrie View Post
we must use a prefix zero if the secret datapacket is smaller then 16(dec) or F(hex), is this correct ?
Actually smaller than 16(dec) = 10(hex). As the conversion from hex back to bytes assumes each byte is represented by a 2 character hex number then the original byte to hex must make sure that each bytes maps to a 2 character hex number. The library only produces a single hex character for values less than 16 so the "0" needs to be added to make it 2 characters.

Quote:
And if so is this than a bug or just stupid programming from me
Neither, just a "feature" of the library you didn't know about.
Reply With Quote
  #19 (permalink)  
Old 06-02-2008, 08:49 PM
Junior Member
 
Join Date: May 2007
Posts: 16
Default

Oke, still working on this problem. Now if the original stringlength is unequal ie 15 etc. then the i in the For .... next statement will only go to 7. Is there a function to decide if the stringlength is unequal or equal. I don't know if i stated it correct, but i mean can the stringlength be divided by 2.

Arrie
Reply With Quote
  #20 (permalink)  
Old 06-02-2008, 09:34 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

Quote:
Originally Posted by Arrie View Post
Oke, still working on this problem.
You seem to be looking at the problem from the wrong end. The solution is in my post #15 above which you put in the encryption app to make sure the string length is an even number of characters.
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:49 AM.


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