求 C#.net 代码改写成VB代码

源代码在:http://tieba.baidu.com/f?kz=600543296在这里发不了。。。... 源代码在:http://tieba.baidu.com/f?kz=600543296

在这里发不了。。。
展开
 我来答
坚戈
2009-06-28 · TA获得超过1166个赞
知道小有建树答主
回答量:1325
采纳率:0%
帮助的人:847万
展开全部
以下是转换结果
给你网址 下次你可以自己转
如果考人工帮转 估计200分也没人帮你
http://www.developerfusion.com/tools/convert/csharp-to-vb/

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

Namespace _3desdiaoyong
''' <summary>
''' Pay_3des 的摘要说明。
''' </summary>
Public Class Pay_3des
Public Sub New()
'
' TODO: 在此处添加构造函数逻辑
'
End Sub
#Region "TripleDESEncrypt 3DES加密自定义字节位填充类型"
''' <summary>
''' 3DES加密自定义字节位填充类型
''' </summary>
''' <param name="encryptSource">加密的数据源</param>
''' <param name="encryptKey">加密的密匙</param>
''' <param name="encryptIV">加密的矢量</param>
''' <param name="paddingMode">自定义填充类型</param>
''' <param name="byteNum">自定义字节数</param>
''' <param name="outType">输出字节形式ToHex16,ToBase64</param>
''' <returns>加密串</returns>
Public Shared Function TripleDESEncrypt(ByVal encryptSource As String, ByVal encryptKey As String, ByVal encryptIV As String, ByVal paddingMode As System.Security.Cryptography.PaddingMode, ByVal byteNum As Integer, ByVal outType As String) As String
'构造一个对称算法
Dim mCSP As SymmetricAlgorithm = New TripleDESCryptoServiceProvider()

Dim ct As ICryptoTransform
Dim ms As MemoryStream
Dim cs As CryptoStream
Dim byt As Byte()

If outType = "" OrElse outType Is Nothing Then
Return "输出配置不能空"
End If
If (encryptKey.Trim().Length) <> byteNum Then
Return "加密字节"
End If
Dim Key As Byte() = System.Text.Encoding.[Default].GetBytes(encryptKey)
mCSP.Key = Key
'默认矢量
If encryptIV = "" OrElse encryptIV Is Nothing Then
encryptIV = encryptKey.Substring(0, 8)
End If
mCSP.IV = System.Text.Encoding.[Default].GetBytes(encryptIV)

'指定加密的运算模式
mCSP.Mode = System.Security.Cryptography.CipherMode.ECB
'获取或设置加密算法的填充模式
mCSP.Padding = paddingMode

ct = mCSP.CreateEncryptor(mCSP.Key, mCSP.IV)

byt = System.Text.Encoding.[Default].GetBytes(encryptSource.Trim())

ms = New MemoryStream()
cs = New CryptoStream(ms, ct, CryptoStreamMode.Write)
cs.Write(byt, 0, byt.Length)
cs.FlushFinalBlock()
cs.Close()

Dim mToString As String = String.Empty
'输出16进制字符
If outType = "ToHex16" Then
mToString = Pay_3des.ToHexString(ms.ToArray())
End If
'输出ToBase64字符
If outType = "ToBase64" Then
mToString = Convert.ToBase64String(ms.ToArray()).ToString().Replace(vbNullChar, "")
End If

Return mToString
End Function
#End Region

#Region "ToHexString 将字节数组转换为字符串"
''' <summary>
''' 字符
''' </summary>
Public Shared HexDigits As Char() = {"0"c, "1"c, "2"c, "3"c, "4"c, "5"c, _
"6"c, "7"c, "8"c, "9"c, "A"c, "B"c, _
"C"c, "D"c, "E"c, "F"c}
''' <summary>
''' 将字节数组转换为字符串
''' </summary>
''' <param name="bytes"></param>
''' <returns></returns>
Public Shared Function ToHexString(ByVal bytes As Byte()) As String
Dim chars As Char() = New Char(bytes.Length * 2 - 1) {}
For i As Integer = 0 To bytes.Length - 1
Dim b As Integer = bytes(i)
chars(i * 2) = HexDigits(b >> 4)
chars(i * 2 + 1) = HexDigits(b And &Hf)
Next
Return New String(chars)
End Function
#End Region
#Region "TripleDESDecrypt 3DES解密"
''' <summary>
''' 3DES解密
''' </summary>
''' <param name="decryptSource">解密的数据源</param>
''' <param name="decryptKey">解密的密匙</param>
''' <param name="decryptIV">解密的矢量</param>
''' <param name="paddingMode">填充模式</param>
''' <param name="byteNum">字节</param>
''' <param name="outType">解密字节形式ToHex16,ToBase64</param>
''' <returns>解密串</returns>
Public Shared Function TripleDESDecrypt(ByVal decryptSource As String, ByVal decryptKey As String, ByVal decryptIV As String, ByVal paddingMode As System.Security.Cryptography.PaddingMode, ByVal byteNum As Integer, ByVal outType As String) As String
'构造一个对称算法
Dim mCSP As SymmetricAlgorithm = New TripleDESCryptoServiceProvider()

Dim ct As ICryptoTransform
Dim ms As MemoryStream
Dim cs As CryptoStream
Dim byt As Byte() = New Byte(-1) {}

If outType = "" OrElse outType Is Nothing Then
Return "解密配置不能空"
End If
If (decryptKey.Trim().Length) <> byteNum Then

Return "解密字节错误"
End If

Dim Key As Byte() = System.Text.Encoding.[Default].GetBytes(decryptKey.Trim())

mCSP.Key = Key
'默认矢量
If decryptIV = "" OrElse decryptIV Is Nothing Then
decryptIV = decryptKey.Substring(0, 8)
End If
mCSP.IV = System.Text.Encoding.[Default].GetBytes(decryptIV)

mCSP.Mode = System.Security.Cryptography.CipherMode.ECB
mCSP.Padding = paddingMode
ct = mCSP.CreateDecryptor(mCSP.Key, mCSP.IV)

'输出16进制字符
If outType = "ToHex16" Then
byt = ConvertHexToBytes(decryptSource)
End If
'输出ToBase64字符
If outType = "ToBase64" Then
byt = Convert.FromBase64String(decryptSource)
End If
ms = New MemoryStream()
cs = New CryptoStream(ms, ct, CryptoStreamMode.Write)
cs.Write(byt, 0, byt.Length)
cs.FlushFinalBlock()
cs.Close()

Return Encoding.[Default].GetString(ms.ToArray()).Replace(vbNullChar, "").Trim()
End Function
#End Region
#Region "ConvertIntToBytes将进制字符串转化为字节数组"
''' <summary>
''' 将进制字符串转化为字节数组
''' </summary>
''' <param name="value"></param>
''' <returns></returns>
Public Shared Function ConvertHexToBytes(ByVal value As String) As Byte()
Dim len As Integer = value.Length / 2
Dim ret As Byte() = New Byte(len - 1) {}
For i As Integer = 0 To len - 1
ret(i) = CByte((Convert.ToInt32(value.Substring(i * 2, 2), 16)))
Next
Return ret
End Function
#End Region
End Class
End Namespace

参考资料: http://www.developerfusion.com/tools/convert/csharp-to-vb/

推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式