Need help understanding Crypto

Discussion in 'Questions (Windows Mobile)' started by tsteward, Sep 15, 2008.

  1. tsteward

    tsteward Active Member Licensed User

    I need help understanding how to use crypto.
    Below is the code from the help file.
    I have modified the sub so as to attempt to decrypt a string that had been previously encrypted.
    Obviously I am doing it wrong.
    Please run the code and click decrypt without doing anything else. I am trying to supply and encrypted string and decode it.

    Code:
    Sub Globals
          
    Dim string(0As Byte, secret(0As Byte 
                            
    Dim NewArray(0)
          PassPhrase = 
    "my key" 'This is not recommended in real applications!!!   
    End Sub


    Sub App_Start
          Form1.Show
          
    Bit.New1
          Crypto.New1
    End Sub


    Sub btnEncrypt_Click
          
    string() = Bit.StringToBytes(txtString.Text,0,StrLength(txtString.Text)) '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
          txtString.Text = s
    End Sub


    Sub btnDecrypt_Click
          
    '4ba21d28c8bf314927966675a8f1a46c this is "Hello World" encrypted
          secret()=Bit.StringToBytes("4ba21d28c8bf314927966675a8f1a46c",0,StrLength("4ba21d28c8bf314927966675a8f1a46c"))
          
    string() = Crypto.Decrypt(PassPhrase,secret()) 'Decrypt the data.
          txtString.Text = Bit.BytesToString(string(),0,ArrayLen(string())) 'Convert the array to a string.
    End Sub
     
  2. agraham

    agraham Expert Licensed User

Loading...
  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