![]() |
|
|||||||
| Home | Register | FAQ | Members List | Search | Today's Posts | Mark Forums Read |
| Questions & Help Needed Post any question regarding Basic4ppc. |
![]() |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
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 |
|
||||
|
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 |
|
|||
|
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 |
|
|||
|
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 |
|
||||
|
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 |
|
|||
|
Quote:
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 |
|
||||
|
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 |
|
|||
|
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 |
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
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 |