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.

Crypto error

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-30-2008, 03:55 PM
Junior Member
 
Join Date: Mar 2008
Posts: 46
Default Crypto error

I don't find solution to solve an error in this routine:

Sub Globals
Dim data(32768) As Byte, strings(102) As Byte, secret(0) As Byte, strbyte(0) As byte, temp(0) As Byte
Dim Buffer(4096) As byte, FotoR(100), URL, sum
Dim number(0) As int32
Dim Etot(8) As Byte
PassPhrase = "Passphrase numero uno 1 3243565476878878767"
PassPhrase2 = "Passphrase numero due 21 457889867684332423"
End Sub

Sub App_Start
Form1.show
End Sub
Sub Button1_Click
bit.New1
crypto.New1
secodes = "ed-4b-6f-39-e0-6e-4b-6d-b3-c-83-d4-ff-f7-80-59-bf-28-f2-a1-b7-ab-47-39-bd-42-3b-8a-a6-de-96-16-4a-3d-ee-4d-65-7e-31-e4-e2-66-2-1d-c0-c0-b4-8e-19-2a-2e-b7-bd-43-33-95-fe-e9-80-bb-c8-75-f1-5c-3e-a2-ba-80-52-64-6-d7-f5-10-95-9b-18-99-3c-12-f5-91-bd-de-ca-3a-78-37-37-84-5d-f5-d4-b1-3d-f2-9a-b2-5f-ea-20-eb-3b-76"
secret() = StrSplit(secodes,"-")
For i = 0 To ArrayLen(secret())-1
secret(i)=bit.HexToDec(secret(i))
Next
strings() = crypto.Decrypt(passphrase2,secret())
stringa = Bit.bytestostring(strings(),0,102)

The given back error is “crypto error” and comes in block letter given back in correspondence of the bold line.
Some idea? Thanks in advance…
Reply With Quote
  #2 (permalink)  
Old 07-30-2008, 04:42 PM
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 problem is this line

secret() = StrSplit(secodes,"-")

By reassigning the secret array with the return of StrSplit you are changing it from an array of Bytes to an array of Strings which is what StrSplit returns.

I have had a private discussion with Erel about this sort of thing because allowing arrays to change type can cause hard to explain errors. I personally would rather that once an array was Dimmed it had to keep its type thereafter.

HexToBytes in my ByteConverter libarary http://www.basic4ppc.com/forum/addit...r-library.html should do what you want.

EDIT

I should have looked a bit further as well. This line isn't doing what you think

secret(i)=bit.HexToDec(secret(i))
Code:
secret() = StrSplit(secodes,"-"' array of strings - each of two hex characters
For i = 0 To ArrayLen(secret())-1
secret(i)=
bit.HexToDec(secret(i)) ' each string now a string representation of the decimal value of the hex.
Next
I know that the help for HexToDec says it returns an Int32, it does but B4ppc converts it to a string to store it.

Last edited by agraham : 07-30-2008 at 04:54 PM.
Reply With Quote
  #3 (permalink)  
Old 07-31-2008, 09:49 AM
Junior Member
 
Join Date: Mar 2008
Posts: 46
Default

Thanks agraham for your prompt reply and your help!
Reply With Quote
  #4 (permalink)  
Old 07-31-2008, 11:00 AM
Junior Member
 
Join Date: Mar 2008
Posts: 46
Default

okey, maked a little mod to source code.
now i have another problem about strsplit byte to string conversion.
if i have i string like this:
"241-241-61-4-212-216-106-192-246-182-207-222-206-251-221-61-13-24-211-176-1-20-126-24-255-214-44-26-31-68-106-180-240-89-54-222-1-185-94-9-112-252-118-51-172-220-124-104-232-111-215-156-85-21-65-126-96-10-243-198-201-159-86-254-199-2-202-90-130-3-147-201-204-157-144-70-130-124-251-69-234-101-166-148-54-79-168-166-162-173-140-72-61-172-173-29-56-98-119-122-65-42-65-30-60-185-97-16-3-151-196-46-135-180-120-109-154-107-69-229-171-82-119-130-47-37-204-219"
Every number is a byte. For example, 219 do not rappresent the number 219, but a character.
But strsplit change it to a string, and i can't process it as a byte.
Are there a way to have it after the split as a byte and not a string?
Thank you again.
Reply With Quote
  #5 (permalink)  
Old 07-31-2008, 11:39 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

If you are starting with a Hex string as in your first post then use my BytesConverter library as I already said - ByteConv is a ByteConverter object
Code:
secodes = "ed-4b-6f-39-e0-6e-4b-6d-b3-c-83-d4-ff-f7-80-59-bf-28-f2-a1-b7-ab-47-39-bd-42-3b-8a-a6-de-96-16-4a-3d-ee-4d-65-7e-31-e4-e2-66-2-1d-c0-c0-b4-8e-19-2a-2e-b7-bd-43-33-95-fe-e9-80-bb-c8-75-f1-5c-3e-a2-ba-80-52-64-6-d7-f5-10-95-9b-18-99-3c-12-f5-91-bd-de-ca-3a-78-37-37-84-5d-f5-d4-b1-3d-f2-9a-b2-5f-ea-20-eb-3b-76"
secret() = HexToBytes(secodes)
strings() = crypto.Decrypt(passphrase2,secret())
If you already have the string as decimals then do something like this (I haven't actually run this so there may be an error).
Code:
secodes = "241-241-61-4-212-216-106-192-246-182-207-222-206-251-221-61-13-24-211-176-1-20-126-24-255-214-44-26-31-68-106-180-240-89-54-222-1-185-94-9-112-252-118-51-172-220-124-104-232-111-215-156-85-21-65-126-96-10-243-198-201-159-86-254-199-2-202-90-130-3-147-201-204-157-144-70-130-124-251-69-234-101-166-148-54-79-168-166-162-173-140-72-61-172-173-29-56-98-119-122-65-42-65-30-60-185-97-16-3-151-196-46-135-180-120-109-154-107-69-229-171-82-119-130-47-37-204-219"
temp() = StrSplit(secodes,
"-"' don't assign it to secret or you change its type to string from byte
len = ArrayLen(temp()
Dim secret(len) As Byte
For i = 0 To len - 1
  secret(i)=temp(i) 
' B4ppc knows secret is a byte array and should convert it
Next
strings() = crypto.Decrypt(passphrase2,secret())
Also "stringa = Bit.bytestostring(strings(),0,102)" may not do what you expect if you have values greater than 127 in the byte array. If you used Bit.New1 then you will get "squares" for any value greater than 127. If you used New2 with a codepage the characters greater than 127 depend upon the code page specified.
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
Need help understanding Crypto tsteward Questions (Windows Mobile) 1 09-15-2008 01:23 PM
Crypto Error Raytracer Italian Forum 0 07-30-2008 03:39 PM
Crypto - Which algorithm is used? Nycran Questions (Windows Mobile) 12 12-09-2007 07:45 PM
Crypto library was updated - 1.10 Erel Announcements 2 10-19-2007 07:44 AM


All times are GMT. The time now is 10:10 AM.


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