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

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

Questions (Windows Mobile) Post any question regarding Basic4ppc.

CryptoEx - I'm missing something here :(

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 10-12-2008, 12:03 AM
LineCutter's Avatar
Senior Member
 
Join Date: May 2007
Location: Daarsit
Posts: 161
Awards Showcase
Beta Tester 
Total Awards: 1
Unhappy CryptoEx - I'm missing something here :(

I'm still trying to get my head around the encryption potential of B4PPC. I just can't get the hang of it.

I've slimmed down the code, which is attached. The password is sent to the sub, where it is converted to an MD5 hash & then the first 64 bits are used as the key for DES object. This encrypts the string & saves it.

The decrypt routine then attempts to reverse the process.

Taking the encryption out leaves me with a spare character at the end of the string, but otherwise works as planned. (The string terminator I guess)

The table is of no significance here (it's never used).

Can anyone see what I've done wrong??
Attached Files
File Type: sbp TableEncryptExMinimal.sbp (1.6 KB, 13 views)
Reply With Quote
  #2 (permalink)  
Old 10-12-2008, 11:21 AM
agraham's Avatar
Basic4ppc Expert
 
Join Date: Jul 2007
Location: Cheshire, UK
Posts: 6,072
Awards Showcase
Innovator medal Beta Tester Forum Contributer 
Total Awards: 3
Default

The attached code works. As I am using the next beta an sbp file may not load on your system so it is in text form to copy and paste into the IDE. The main thing for simple use is to use Mode 2 which avoids using inialisation vctors (IVs) for block chaining. Your problem was that the IV on encryption was not the same as the IV on decryption as Crypto.New1 creats a new random IV each time (The help incorrectly states that the default IV is all zeroes it appeared like that on testing but is apparently not true )

I don't' understand "Taking the encryption leaves ..." but after decryption of a string there are spare bytes that have been used to pack the string to a muliple of 8 bytes. I've tried to explain this in the comments in DesDemo.sbp. The output from DecryptString should strip them off. Bad data complaints on DecryptString arise because when decrypted these packing bytes are not within the valid range - they have specific values to tell DecryptString how many bytes were added as packing.

You also had an unneeded extra parameter in DecryptString.
Reply With Quote
  #3 (permalink)  
Old 10-12-2008, 11:48 AM
LineCutter's Avatar
Senior Member
 
Join Date: May 2007
Location: Daarsit
Posts: 161
Awards Showcase
Beta Tester 
Total Awards: 1
Default

Thanks!

Hopefully this will help more people than me.

(The "taking out the encryption" refers to bf.writebytes() when applied to the array of bytes returned from the string with bit.stringtobytes(). I've attached the sbp in case that's not clear enough. I'm more than happy with the working code as a skeleton for the routine I need, which strangely enough uses the table on the form.)
Reply With Quote
  #4 (permalink)  
Old 10-12-2008, 11:56 AM
agraham's Avatar
Basic4ppc Expert
 
Join Date: Jul 2007
Location: Cheshire, UK
Posts: 6,072
Awards Showcase
Innovator medal Beta Tester Forum Contributer 
Total Awards: 3
Default

The extra byte is because when you open a file in cRandom mode it is never truncated so because you already had an 8 byte long file from when you were trying to encrypt it stays at 8 bytes even when you store fewer bytes in it. Look at the beginning of the code I just posted. I aded a test and delete of test.enc to pre-empt this very problem.
Reply With Quote
  #5 (permalink)  
Old 10-12-2008, 12:23 PM
LineCutter's Avatar
Senior Member
 
Join Date: May 2007
Location: Daarsit
Posts: 161
Awards Showcase
Beta Tester 
Total Awards: 1
Default

Thanks again! I suspect that you've just saved me a rather irritating debugging session trying to track this down. Hopefully, if I keep reading the forum & learning this sort of thing I'll be able to stop asking similar questions.
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
CryptoEX library agraham Additional Libraries 14 11-03-2011 12:54 PM
CryptoEx and Exceptions manuals are online Erel Announcements 0 05-17-2008 01:20 PM
Tab Control dll missing Graley Questions (Windows Mobile) 2 01-02-2008 04:10 PM
Missing DLL willisgt Questions (Windows Mobile) 1 12-13-2007 04:23 AM
Missing posts Cableguy Forum Discussion 1 07-23-2007 06:51 PM


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


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