Encryption In Asp.net

Discussion in 'Software' started by ava_h, Oct 21, 2006.

  1. ava_h

    ava_h

    Joined:
    Oct 14, 2006
    Messages:
    2
    please help me!
    i want to encrypte my string but when
    i decrypte it the exception {"Length of the data to decrypt is invalid."}
    occur.
    what is the problem?
    my code:

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim iv As Byte() = {240, 32, 45, 29, 0, 76, 173, 59}
    Dim cryptokey As String = "this is a test"
    Dim mystring As String = TextBox1.Text
    Dim buffer As Byte() = System.Text.Encoding.ASCII.GetBytes(mystring)
    Dim des As TripleDESCryptoServiceProvider = New TripleDESCryptoServiceProvider
    Dim md5 As MD5CryptoServiceProvider = New MD5CryptoServiceProvider
    des.Key = md5.ComputeHash(System.Text.ASCIIEncoding.ASCII.GetBytes(cryptokey))
    des.IV = iv
    Dim codedbuffer As Byte() = des.CreateEncryptor.TransformFinalBlock(buffer, 0, buffer.Length)
    Label1.Text = System.Convert.ToBase64String(codedbuffer, 0, codedbuffer.Length)

    End Sub

    Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
    Dim iv As Byte() = {240, 32, 45, 29, 0, 76, 173, 59}

    Dim cryptokey As String = "this is a test"
    Dim codedstring As String = Label1.Text
    '
    Dim buffer As Byte() = System.Text.Encoding.ASCII.GetBytes(codedstring)
    Dim des As TripleDESCryptoServiceProvider = New TripleDESCryptoServiceProvider
    Dim md5 As MD5CryptoServiceProvider = New MD5CryptoServiceProvider
    des.Key = md5.ComputeHash(System.Text.ASCIIEncoding.ASCII.GetBytes(cryptokey))
    des.IV = iv
    Dim codedbuffer As Byte() = des.CreateDecryptor.TransformFinalBlock(buffer, 0, buffer.Length)
    Label2.Text = System.Convert.ToBase64String(codedbuffer, 0, codedbuffer.Length)
    End Sub
     
    ava_h, Oct 21, 2006
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?c2FuanU=?=

    information about asp ,oracle,asp.net certification?

    =?Utf-8?B?c2FuanU=?=, May 18, 2005, in forum: Microsoft Certification
    Replies:
    1
    Views:
    671
    Bob Christian
    May 18, 2005
  2. Zabron Muyambo

    Easy Moving from ASP to ASP.NET???

    Zabron Muyambo, Oct 26, 2004, in forum: MCSD
    Replies:
    7
    Views:
    539
    Zabron Muyambo
    Oct 27, 2004
  3. thehobbit
    Replies:
    0
    Views:
    3,894
    thehobbit
    Nov 22, 2006
  4. imman

    session from asp to asp.net

    imman, Feb 20, 2008, in forum: General Computer Support
    Replies:
    0
    Views:
    949
    imman
    Feb 20, 2008
  5. london1919
    Replies:
    1
    Views:
    3,057
    Lawrence Garvin \(MVP\)
    Dec 8, 2008
Loading...

Share This Page