Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net mvc Web服务中的加密与主项目中的加密结果不同_Asp.net Mvc_Vb.net_Web Services_Encryption_Web - Fatal编程技术网

Asp.net mvc Web服务中的加密与主项目中的加密结果不同

Asp.net mvc Web服务中的加密与主项目中的加密结果不同,asp.net-mvc,vb.net,web-services,encryption,web,Asp.net Mvc,Vb.net,Web Services,Encryption,Web,我试图将一个加密字符串从web服务传递到我的主项目,但当我试图执行解密时,它返回“Base-64字符数组或字符串的长度无效”。因为我的主项目中的加密结果与web服务中的加密结果不同,但我只是使用相同的加密 示例(“SessionExpired”): Web服务加密-> tDaxnTVCaLOxWSIYVZLO5lxJm%2Bx1VG1CCEPXF1DBLK%3d 主项目加密-> tDaxnTVCaLOxWSIYVZLO5lxJm%252BX1VG1GCCEPXF1DBLK%253d 加解密码

我试图将一个加密字符串从web服务传递到我的主项目,但当我试图执行解密时,它返回“Base-64字符数组或字符串的长度无效”。因为我的主项目中的加密结果与web服务中的加密结果不同,但我只是使用相同的加密

示例(“SessionExpired”):

Web服务加密-> tDaxnTVCaLOxWSIYVZLO5lxJm%2Bx1VG1CCEPXF1DBLK%3d

主项目加密-> tDaxnTVCaLOxWSIYVZLO5lxJm%252BX1VG1GCCEPXF1DBLK%253d

加解密码

    Public Function password_encrypt(clearText As String) As String
        Dim EncryptionKey As String = "MAKV2SPBNI99212"
        Dim clearBytes As Byte() = Encoding.Unicode.GetBytes(clearText)
        Using encryptor As Aes = Aes.Create()
            Dim pdb As New Rfc2898DeriveBytes(EncryptionKey, New Byte() {&H49, &H76, &H61, &H6E, &H20, &H4D,
             &H65, &H64, &H76, &H65, &H64, &H65,
             &H76})
            encryptor.Key = pdb.GetBytes(32)
            encryptor.IV = pdb.GetBytes(16)
            Using ms As New MemoryStream()
                Using cs As New CryptoStream(ms, encryptor.CreateEncryptor(), CryptoStreamMode.Write)
                    cs.Write(clearBytes, 0, clearBytes.Length)
                    cs.Close()
                End Using
                clearText = Convert.ToBase64String(ms.ToArray())
            End Using
        End Using
        Return clearText
    End Function

    Public Function password_decrypt(cipherText As String) As String
        If cipherText <> Nothing Then
            Dim EncryptionKey As String = "MAKV2SPBNI99212"
            Dim cipherBytes As Byte() = Convert.FromBase64String(cipherText)
            Using encryptor As Aes = Aes.Create()
                Dim pdb As New Rfc2898DeriveBytes(EncryptionKey, New Byte() {&H49, &H76, &H61, &H6E, &H20, &H4D,
             &H65, &H64, &H76, &H65, &H64, &H65,
             &H76})
                encryptor.Key = pdb.GetBytes(32)
                encryptor.IV = pdb.GetBytes(16)
                Using ms As New MemoryStream()
                    Using cs As New CryptoStream(ms, encryptor.CreateDecryptor(), CryptoStreamMode.Write)
                        cs.Write(cipherBytes, 0, cipherBytes.Length)
                        cs.Close()
                    End Using
                    cipherText = Encoding.Unicode.GetString(ms.ToArray())
                End Using
            End Using
        End If
        Return cipherText
    End Function
公共函数密码\u加密(明文为字符串)为字符串
Dim EncryptionKey As String=“MAKV2SPBNI99212”
Dim clearBytes As Byte()=Encoding.Unicode.GetBytes(明文)
将加密程序用作Aes=Aes.Create()
将pdb设置为新的Rfc2898DeriveBytes(加密密钥,新字节(){&H49、&H76、&H61、&H6E、&H20、&H4D,
&H65、H64、H76、H65、H64、H65、,
&H76})
encryptor.Key=pdb.GetBytes(32)
encryptor.IV=pdb.GetBytes(16)
将ms用作新内存流()
将cs用作新的加密流(ms,encryptor.CreateEncryptor(),CryptoStreamMode.Write)
cs.Write(clearBytes,0,clearBytes.Length)
政务司司长(关闭)
终端使用
clearText=Convert.tobase64字符串(ms.ToArray())
终端使用
终端使用
返回明文
端函数
公用函数密码\u解密(密文为字符串)为字符串
如果密文什么都没有,那么
Dim EncryptionKey As String=“MAKV2SPBNI99212”
Dim cipherBytes As Byte()=Convert.FromBase64String(密文)
将加密程序用作Aes=Aes.Create()
将pdb设置为新的Rfc2898DeriveBytes(加密密钥,新字节(){&H49、&H76、&H61、&H6E、&H20、&H4D,
&H65、H64、H76、H65、H64、H65、,
&H76})
encryptor.Key=pdb.GetBytes(32)
encryptor.IV=pdb.GetBytes(16)
将ms用作新内存流()
使用cs作为新的加密流(ms,encryptor.CreateDecryptor(),CryptoStreamMode.Write)
cs.写入(cipherBytes,0,cipherBytes.长度)
政务司司长(关闭)
终端使用
cipherText=Encoding.Unicode.GetString(ms.ToArray())
终端使用
终端使用
如果结束
返回密文
端函数

密码应该是散列的,而不是加密的。如果不想使用
Rfc2898DeriveBytes
class@Plutonix我实际上并没有加密密码,它只是一个我试图加密并传递的代码,这样当用作查询字符串时,用户就不容易读取它。它只是说密码加密,因为我忘了编辑它,我的坏。密码应该散列而不是加密。如果不想使用
Rfc2898DeriveBytes
class@Plutonix我实际上并没有加密密码,它只是一个我试图加密并传递的代码,这样当用作查询字符串时,用户就不容易读取它。它只是说密码加密,因为我忘了编辑它,我的坏。