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
Dim Secret(StrLength(Nickname)/2) As byte
For i = 0 To ArrayLen(Secret()) - 1
Secret(i) = Bit.HexToDec(SubString(Nickname, i*2, 2))
Next
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
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.It appears when the original stringlength<6 everything works fine, but when it is 6 or more the abovementioned errormessage is shown.
For i = 0 To ArrayLen(secret())-1
If secret(i)< 16 Then s = s & "0"
s = s & bit.DecToHex(secret(i))
Next
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.we must use a prefix zero if the secret datapacket is smaller then 16(dec) or F(hex), is this correct ?
Neither, just a "feature" of the library you didn't know about.And if so is this than a bug or just stupid programming from me
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.Oke, still working on this problem.
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?