哪位大大帮忙改进下这个DES加密解密函数
这是使用.net里自带的DES加密解密函数的,但是速度不够快,用这里两个函数对1000000行每行30个字符的文件加密,在我电脑(Intel(R) Pentium(R) Dual T2330 1.6G双核,1G内存)上面加密需要23秒,解密需要17秒。但是老顶说速度不够,实在想不出办法了,哪位大大帮忙改进下,不胜感激。
下面是这两个函数:
Imports System.Security
Imports System.Security.Cryptography
Imports System.Text
Imports
Module ModDES
Public pwd As String = "12345678" 'DES加密解密的密码,必须是8位
'加密函数
Public Function Encrypt(ByVal StrInput As String) As String
Dim des As New DESCryptoServiceProvider()
des.Key = ASCIIEncoding.ASCII.GetBytes(pwd)
des.IV = ASCIIEncoding.ASCII.GetBytes(pwd)
Dim ByteArrayInput As [Byte]() = Encoding.Default.GetBytes(StrInput)
Dim ms As New ()
'使用 DES 加密法转换 stream 成 CryptoStream
'8位数字, 8个字
Dim CryptoStream As New CryptoStream(ms, des.CreateEncryptor(des.Key, des.IV), CryptoStreamMode.Write)
'写入 DES 加密
CryptoStream.Write(ByteArrayInput, 0, ByteArrayInput.Length)
CryptoStream.FlushFinalBlock()
des.Clear()
Return Convert.ToBase64String(ms.ToArray())
End Function
'解密函数
Public Function Decrypt(ByVal StrInput As String) As String
Dim des As New DESCryptoServiceProvider()
DES.Key = ASCIIEncoding.ASCII.GetBytes(pwd)
DES.IV = ASCIIEncoding.ASCII.GetBytes(pwd)
Dim ByteArrayInput As [Byte]() = Convert.FromBase64String(StrInput)
Dim ms As New ()
'使用 DES 解密法转换 bytes 成 CryptoStream
Dim CryptoStream As New CryptoStream(ms, DES.CreateDecryptor(DES.Key, DES.IV), CryptoStreamMode.Write)
CryptoStream.Write(ByteArrayInput, 0, ByteArrayInput.Length)
CryptoStream.FlushFinalBlock()
des.Clear()
Return Encoding.Default.GetString(ms.ToArray())
End Function
End Module