微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

System.Security.Cryptography.CryptographicException: '错误数据 ' 三重 DES 加密 vb.net ms access

如何解决System.Security.Cryptography.CryptographicException: '错误数据 ' 三重 DES 加密 vb.net ms access

加解密

Imports System.Security.Cryptography
Imports System.Text
Imports System.IO



Public Class EncDeccls

    Private tripleDES As New TripleDESCryptoServiceProvider

    'Public Sub New(_KEY As String)
    '    KeyStr = _KEY
    'End Sub

    'Private keyvalue As String
    'Public Property Keystr() As String
    '    Get
    '        Return keyvalue
    '    End Get
    '    Set(value As String)
    '        keyvalue = value
    '    End Set
    'End Property

    Function Encryption(ByVal datafile As String) As String

        Dim input As Byte() = System.Text.Encoding.Unicode.GetBytes(datafile)

        Dim ms As New System.IO.MemoryStream
        Dim encstream As New CryptoStream(ms,tripleDES.CreateEncryptor(),System.Security.Cryptography.CryptoStreamMode.Write)

        encstream.Write(input,input.Length)

        encstream.FlushFinalBlock()

        Return Convert.ToBase64String(ms.ToArray)

    End Function

    Function Decryption(ByVal encryptedfile As String) As String

        Dim output() As Byte = System.Text.Encoding.Unicode.GetBytes(encryptedfile)

        Dim ms As New System.IO.MemoryStream
        Dim decstream As New CryptoStream(ms,tripleDES.CreateDecryptor(),System.Security.Cryptography.CryptoStreamMode.Write)

        decstream.Write(output,output.Length)

        decstream.FlushFinalBlock()

        Return System.Text.Encoding.Unicode.GetString(ms.ToArray)
    End Function
End Class

数据库中检索数据并解密,然后在datagridview(DGVSV)上显示代码

Dim cmd1 As New OleDbCommand("SELECT * FROM pwdmgr WHERE username = @uname",conn)
        cmd1.Parameters.Add("@uname",OleDbType.VarChar).Value = x
        conn.open()
        dr = cmd1.ExecuteReader
        dr.Read()
        DGVSV.Rows.Add(dr.Item("id").ToString,EncryptDecryptFiles.Decryption(dr.Item("email").ToString),EncryptDecryptFiles.Decryption(dr.Item("pwd").ToString))
        
        conn.Close()

有几行数据需要检索并将其显示到数据网格视图(DGVSV)中。每次当我在上面运行此函数时,它都会显示错误 System.Security.Cryptography.CryptographicException: 'Bad Data. '

有人可以帮助我吗?

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。