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


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

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

帅哥哟,离线,有人找我吗?
z769036165
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | 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编辑过]

 回到顶部