尝试解密vb中的电子邮件地址时出错

时间:2012-10-03 20:23:25

标签: asp.net vb.net encryption vb.net-2010

我正在尝试解密VB.NET中的电子邮件地址,但我收到一个错误:“Base-64字符数组的长度无效。”

发送错误的电子邮件地址:abcadmin@googlemail.com

可以正常使用的电子邮件地址:admin@yahoo.com

解密代码:

  Private Function Decrypt(ByVal strText As String, ByVal sDecrKey _
               As String) As String
        Dim byKey() As Byte = {}
        Dim IV() As Byte = {&H12, &H34, &H56, &H78, &H90, &HAB, &HCD, &HEF}
        Dim inputByteArray(strText.Length) As Byte

        Try


            byKey = System.Text.Encoding.UTF8.GetBytes(Left("ABCD9876_", 8))
            Dim des As New DESCryptoServiceProvider()
            inputByteArray = Convert.FromBase64String(strText)
            Dim ms As New MemoryStream()
            Dim cs As New CryptoStream(ms, des.CreateDecryptor(byKey, IV), CryptoStreamMode.Write)

            cs.Write(inputByteArray, 0, inputByteArray.Length)
            cs.FlushFinalBlock()
            Dim encoding As System.Text.Encoding = System.Text.Encoding.UTF8

            Return encoding.GetString(ms.ToArray())

        Catch ex As Exception
            Return ex.Message
        End Try

    End Function

提前致谢,Laziale

0 个答案:

没有答案