Foxtable(狐表)用户栏目专家坐堂 → [求助]请修改为Foxtable可用的方法


  共有2137人关注过本帖树形打印复制链接

主题:[求助]请修改为Foxtable可用的方法

帅哥哟,离线,有人找我吗?
nsdata
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:幼狐 帖子:162 积分:1505 威望:0 精华:0 注册:2022/11/10 9:07:00
[求助]请修改为Foxtable可用的方法  发帖心情 Post By:2023/12/10 0:46:00 [只看该作者]

  
  蓝老帮忙把下面加、解密的类改成Foxtable可以调用的全局方法,菜鸟的我把代码复制到foxtable报错不知道怎么解决

Imports System.Security.Cryptography
Imports System.Text
//加密
Public Class AESHelper
    Public Shared Function EncryptAES128(ByVal plainText As String, ByVal key As String) As String
        Dim result As String = ""

        Using aes As New AesManaged()
            aes.Mode = CipherMode.ECB
            aes.Padding = PaddingMode.PKCS7
            aes.Key = Encoding.UTF8.GetBytes(key)

            Using encryptor As ICryptoTransform = aes.CreateEncryptor(aes.Key, aes.IV)
                Using ms As New System.IO.MemoryStream()
                    Using cs As New CryptoStream(ms, encryptor, CryptoStreamMode.Write)
                        Dim plainBytes As Byte() = Encoding.UTF8.GetBytes(plainText)
                        cs.Write(plainBytes, 0, plainBytes.Length)
                        cs.FlushFinalBlock()

                        Dim encryptedBytes As Byte() = ms.ToArray()
                        result = Convert.ToBase64String(encryptedBytes)
                    End Using
                End Using
            End Using
        End Using

        Return result
    End Function
End Class



Imports System.Security.Cryptography
Imports System.Text
//解密
Public Class AESHelper
    Public Shared Function DecryptAES128(ByVal encryptedText As String, ByVal key As String) As String
        Dim result As String = ""

        Using aes As New AesManaged()
            aes.Mode = CipherMode.ECB
            aes.Padding = PaddingMode.PKCS7
            aes.Key = Encoding.UTF8.GetBytes(key)

            Using decryptor As ICryptoTransform = aes.CreateDecryptor(aes.Key, aes.IV)
                Dim encryptedBytes As Byte() = Convert.FromBase64String(encryptedText)

                Using ms As New System.IO.MemoryStream(encryptedBytes)
                    Using cs As New CryptoStream(ms, decryptor, CryptoStreamMode.Read)
                        Using reader As New System.IO.StreamReader(cs)
                            result = reader.ReadToEnd()
                        End Using
                    End Using
                End Using
            End Using
        End Using

        Return result
    End Function
End Class

 回到顶部
帅哥哟,离线,有人找我吗?
linyunu1
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:幼狐 帖子:162 积分:1089 威望:0 精华:0 注册:2020/1/16 11:58:00
  发帖心情 Post By:2023/12/10 11:31:00 [只看该作者]

去掉
Imports System.Security.Cryptography
Imports System.Text

然后下面代码补全命名空间 例如 Using aes As New System.Security.Cryptography.AesManaged()

 回到顶部
帅哥哟,离线,有人找我吗?
linyunu1
  3楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:幼狐 帖子:162 积分:1089 威望:0 精华:0 注册:2020/1/16 11:58:00
  发帖心情 Post By:2023/12/10 11:32:00 [只看该作者]

加密和解密的代码并一起

 回到顶部
帅哥哟,离线,有人找我吗?
nsdata
  4楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:幼狐 帖子:162 积分:1505 威望:0 精华:0 注册:2022/11/10 9:07:00
  发帖心情 Post By:2023/12/10 23:47:00 [只看该作者]

   试了也不行,能否上传个demo?

图片点击可在新窗口打开查看此主题相关图片如下:bug.jpg
图片点击可在新窗口打开查看






 回到顶部
帅哥哟,离线,有人找我吗?
z769036165
  5楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:三尾狐 帖子:760 积分:5430 威望:0 精华:0 注册:2012/10/5 21:53:00
  发帖心情 Post By:2023/12/11 8:18:00 [只看该作者]

AES128加密方法
Dim key As String = "12323123"
Dim data As String = "31231231214124123"
Dim encryptedBytes As Byte()
Dim aesAlg As New System.Security.Cryptography.AesCryptoServiceProvider()
aesAlg.Key = Encoding.ASCII.GetBytes(key)
aesAlg.Mode = System.Security.Cryptography.CipherMode.ECB
aesAlg.Padding = System.Security.Cryptography.PaddingMode.PKCS7   '修改类型
Dim encryptor As System.Security.Cryptography.ICryptoTransform = aesAlg.CreateEncryptor(aesAlg.Key, aesAlg.IV)
Dim memoryStream As New System.IO.MemoryStream()
Dim cryptoStream As New System.Security.Cryptography.CryptoStream(memoryStream, encryptor, System.Security.Cryptography.CryptoStreamMode.Write)
Dim dataBytes As Byte() = Encoding.ASCII.GetBytes(data)
cryptoStream.Write(dataBytes, 0, dataBytes.Length)
cryptoStream.FlushFinalBlock()
encryptedBytes = memoryStream.ToArray()
Output.Show(Convert.ToBase64String(encryptedBytes))



AES128解密方法

Dim key As String = "3123123"
Dim encryptedData As String = "PNOK3123AJs/9W3fVko19o="
Dim decryptedBytes As Byte()
Dim aesAlg As New System.Security.Cryptography.AesCryptoServiceProvider()
aesAlg.KeySize = 128
aesAlg.Key = Encoding.ASCII.GetBytes(key)
aesAlg.Mode = System.Security.Cryptography.CipherMode.ECB
aesAlg.Padding = System.Security.Cryptography.PaddingMode.PKCS7  '修改类型

Dim decryptor As System.Security.Cryptography.ICryptoTransform = aesAlg.CreateDecryptor(aesAlg.Key, aesAlg.IV)
Dim encryptedBytes As Byte() = Convert.FromBase64String(encryptedData)
Dim memoryStream As New System.IO.MemoryStream(encryptedBytes)
Dim cryptoStream As New System.Security.Cryptography.CryptoStream(memoryStream, decryptor, System.Security.Cryptography.CryptoStreamMode.Read)
Dim decryptedDataBytes As Byte() = New Byte(encryptedBytes.Length - 1) {}
Dim decryptedLength As Integer = cryptoStream.Read(decryptedDataBytes, 0, decryptedDataBytes.Length)
Dim unpaddedDataBytes As Byte() = New Byte(decryptedLength - 1) {}
Array.Copy(decryptedDataBytes, unpaddedDataBytes, decryptedLength)
decryptedBytes = unpaddedDataBytes
Output.Show(System.Text.ASCIIEncoding.ASCII.GetString(decryptedBytes))
[此贴子已经被作者于2023/12/11 8:18:51编辑过]

 回到顶部
帅哥哟,离线,有人找我吗?
nsdata
  6楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:幼狐 帖子:162 积分:1505 威望:0 精华:0 注册:2022/11/10 9:07:00
  发帖心情 Post By:2023/12/12 0:01:00 [只看该作者]

  
  感谢大神!!

 回到顶部