Crypto error

Discussion in 'Questions (Windows Mobile)' started by Raytracer, Jul 30, 2008.

  1. Raytracer

    Raytracer Member Licensed User

    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
    End Sub
    Sub Button1_Click
    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
    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…
  2. agraham

    agraham Expert Licensed User

    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 should do what you want.


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

    secret() = StrSplit(secodes,"-"' array of strings - each of two hex characters
    For i = 0 To ArrayLen(secret())-1
    bit.HexToDec(secret(i)) ' each string now a string representation of the decimal value of the hex.
    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: Jul 30, 2008
  3. Raytracer

    Raytracer Member Licensed User

    Thanks agraham for your prompt reply and your help!
  4. Raytracer

    Raytracer Member Licensed User

    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:
    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.
  5. agraham

    agraham Expert Licensed User

    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
    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).
    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
    ' B4ppc knows secret is a byte array and should convert it
    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.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice