全局代码
Public Function Encrypt(ByVal toEncrypt As String, ByVal key As String) As String
Dim keyArray = Encoding.GetEncoding("UTF-8").GetBytes(key)
Dim toEncryptArray = Encoding.GetEncoding("UTF-8").GetBytes(toEncrypt)
Using acsp = New System.Security.Cryptography.AesCryptoServiceProvider
acsp.KeySize = 128
acsp.BlockSize = 128
acsp.GenerateIV()
Using aes = New System.Security.Cryptography.AesCryptoServiceProvider
aes.Key = keyArray
aes.IV = acsp.IV
aes.Mode = System.Security.Cryptography.CipherMode.ECB
aes.Padding = System.Security.Cryptography.PaddingMode.PKCS7
Dim resultArray As Byte()
Using cTransform = aes.CreateEncryptor()
resultArray = cTransform.TransformFinalBlock(toEncryptArray, 0, toEncryptArray.Length)
End Using
Return Convert.ToBase64String(resultArray)
End Using
End Using
End Function
Public Function Decrypt(ByVal toDecrypt As String, ByVal key As String) As String
Dim keyArray = Encoding.GetEncoding("GB2312").GetBytes(key)
Dim toDecryptArray = Convert.FromBase64String(toDecrypt)
Using acsp = New System.Security.Cryptography.AesCryptoServiceProvider
acsp.KeySize = 128
acsp.BlockSize = 128
acsp.GenerateIV()
Using aes = New System.Security.Cryptography.AesCryptoServiceProvider
aes.Key = keyArray
aes.IV = acsp.IV
aes.Mode = System.Security.Cryptography.CipherMode.ECB
aes.Padding = System.Security.Cryptography.PaddingMode.PKCS7
Dim resultArray As Byte()
Using cTransform = aes.CreateDecryptor()
resultArray = cTransform.TransformFinalBlock(toDecryptArray, 0, toDecryptArray.Length)
End Using
Return Encoding.GetEncoding("UTF-8").GetString(resultArray)
End Using
End Using
End Function
命令窗口调用
Dim url As String = "http://120.197.89.51/SmsHttpInterface/smsService/Do-sendSms.action"
Dim Eid As String = "qxt"
Dim Userid As String = "admin"
Dim Password As String = "123456"
Dim MessageContent As String = "c#测试短信发送"
Dim Mobiles As String = "13888888888"
Dim ExtendAccessNum As String = ""
Dim key As String = "0000000000000000"
Dim hc As New HttpClient(url)
hc.ContentType = "application/x-www-form-urlencoded" '
hc.FormData.Add("eid",Encrypt(Eid, key).Replace("+", "%2b"))
hc.FormData.Add("userid",Encrypt(Userid, key).Replace("+", "%2b"))
hc.FormData.Add("password",Encrypt(Password, key).Replace("+", "%2b"))
'其它参数参考实例自己补齐
Dim ret As String = hc.GetData
msgbox(Decrypt(ret ,key))
[此贴子已经被作者于2019/10/30 14:51:37编辑过]