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.


Decrypt


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-16-2007, 11:55 PM
Junior Member
 
Join Date: Apr 2007
Location: Leicester, UK
Posts: 16
Default Decrypt

Hi,
I'm having trouble with encrypt/decrypt. I can encrypt the string and display it as an encrypted string but I want to save that (in the registry eventually) to be retrieved later and decrypted. The Cypto example stores the encrypted string as an array to be decrypted. I've tried taking my encrypted string and converting it to an array of bytes and decrypting that but I get a bad data error.
John
Reply With Quote
  #2 (permalink)  
Old 05-17-2007, 12:30 AM
Cableguy's Avatar
Basic4ppc Expert
 
Join Date: Apr 2007
Location: N 41º11'30.30" W 8º39'46.60"
Posts: 1,463
Awards Showcase
Forum Contributer 
Total Awards: 1
Default

Were did you store the cripted data?

If you are trying to read from a file, I think that you must read as a normal file and then pass it to a variable to decript... reding as binary will read also the heading of the file wich is not a valid set of values to decript....
I havent tryed it yet but if you still get errors I'll try to help...
__________________
Paulo Gomes
Porto, Portugal

PC: Dual-Core 1,8Ghz, 2GB RAM, 80GB HD
PPC: Qtek9000, 1GB SD

DLL Version Listing
Reply With Quote
  #3 (permalink)  
Old 05-17-2007, 03:34 AM
Junior Member
 
Join Date: Apr 2007
Posts: 42
Send a message via Yahoo to mwaite
Default

I faced the same problem until I figured out how to handle it...

I use these two subs, built up from the example, to encrypt strings for a registry, and then decrypt back.

Sub EncryptIt(a)
string() = Bit.StringToBytes(a,0,StrLength(a)) 'Convert the string to an array of bytes.
secret() = Crypto.Encrypt(ED, string()) 'Save the encrypted data.

for i = 0 to ArrayLen(secret())-1 'Show the encrypted data in the TextBox
ss = bit.DecToHex(secret(i))
If StrLength(ss)<2 then ss = "0" & ss ' Add leading zero to byte if not two digits!
s = s & ss
next
Return s
End Sub

Sub DecryptIt(aa)
y = StrLength(aa) / 2
Dim NewArray(y) as Byte ' Array may end up being 8, 16, 32... bytes long

For z = 0 to (StrLength(aa) / 2) - 1 ' Hex values are two digits long (8 byte should be 0 to 3 loop)
NewArray(z)= bit.HexToDec(StrAt(aa,z * 2) & StrAt(aa,(z * 2)+1))
Next
if ArrayLen(NewArray()) = 0 then return
string() = Crypto.Decrypt(ED,NewArray()) 'Decrypt the data.
zz = Bit.BytesToString(string(),0,ArrayLen(string())) 'Convert the array to a string.
Return zz
End Sub

Regards,
Mike
Reply With Quote
  #4 (permalink)  
Old 05-17-2007, 08:04 AM
Junior Member
 
Join Date: Apr 2007
Location: Leicester, UK
Posts: 16
Default

Many thanks Mike. Works a treat now.
John
Reply With Quote
  #5 (permalink)  
Old 06-30-2007, 05:38 PM
Knows the basics
 
Join Date: Jun 2007
Location: Netherlands (Arnhem)
Posts: 71
Default

Quote:
Originally Posted by mwaite View Post
I faced the same problem until I figured out how to handle it...
That's why I use your piece of code

I have one question. When I don't put dim NewArray(0) as byte in my Global section, the compiler will crash with an undeclared array .....

So I don't get the point about the Dim NewArray(y) as Byte in the Decryptit Sub. Is this how you redeclare an existing array?

Confused .....

Scub
__________________
PPC: IPAQ 2210, 2GB, CF GPS, CF Wireless
Reply With Quote
  #6 (permalink)  
Old 06-30-2007, 07:57 PM
Cableguy's Avatar
Basic4ppc Expert
 
Join Date: Apr 2007
Location: N 41º11'30.30" W 8º39'46.60"
Posts: 1,463
Awards Showcase
Forum Contributer 
Total Awards: 1
Default

From what i can "read" the code, newarray is were the crypted bytes are passed before decrypt....a sort of temporary way of storing the hole data string before decrypt
__________________
Paulo Gomes
Porto, Portugal

PC: Dual-Core 1,8Ghz, 2GB RAM, 80GB HD
PPC: Qtek9000, 1GB SD

DLL Version Listing
Reply With Quote
  #7 (permalink)  
Old 06-30-2007, 08:17 PM
Knows the basics
 
Join Date: Jun 2007
Location: Netherlands (Arnhem)
Posts: 71
Default

Quote:
Originally Posted by Cableguy View Post
From what i can "read" the code, newarray is were the crypted bytes are passed before decrypt....a sort of temporary way of storing the hole data string before decrypt
What I ment was there are two dim declarations for newarray.
The 1st time in the global section as newarray(0) and the second in the subsection as newarray(y).

When I remove the one in the global section, the compiler think it's missing an undeclared array: newarray(y). But that array is defined with a dim in it's sub.

That confuses me ....... still.

Scub
__________________
PPC: IPAQ 2210, 2GB, CF GPS, CF Wireless
Reply With Quote
  #8 (permalink)  
Old 06-30-2007, 08:22 PM
Cableguy's Avatar
Basic4ppc Expert
 
Join Date: Apr 2007
Location: N 41º11'30.30" W 8º39'46.60"
Posts: 1,463
Awards Showcase
Forum Contributer 
Total Awards: 1
Default

In V5 ALL arrays have to be declared in globals...if one doesnt known the length of the array then set to zero and later re-set to the final length or increment, as in this case, the array length....
__________________
Paulo Gomes
Porto, Portugal

PC: Dual-Core 1,8Ghz, 2GB RAM, 80GB HD
PPC: Qtek9000, 1GB SD

DLL Version Listing
Reply With Quote
  #9 (permalink)  
Old 06-30-2007, 08:36 PM
Knows the basics
 
Join Date: Jun 2007
Location: Netherlands (Arnhem)
Posts: 71
Default

That clarifies it! So a redimension of the array. I was looking for a way to redimension an array at runtime and just found it.

Dim B4PPC(0)
...
IsVeryNice = 250
Dim B4PPC(IsVeryNice)

Thanks Cabelguy
__________________
PPC: IPAQ 2210, 2GB, CF GPS, CF Wireless
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
encrypt in1st app, decrypt in 2nd app Arrie Questions & Help Needed 20 06-02-2008 10:05 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:04 PM.


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