| 编程中国 | 业界新闻 | 技术文章 | 视频教程 | 下载频道 | 程序源码 | 个人空间 | 编程论坛
全能ASP/PHP/ASP.NET主机,支持月付专业 MSSQL 数据库空间,支持月付专业 MySQL 数据库空间,支持月付学习型 ASP/PHP/ASP.NET 主机 30元/年
高端软件开发 = 年薪十万不是梦   
共有 377 人关注过本帖
标题:哪位大大帮忙改进下这个DES加密解密函数
收藏  订阅  推荐  打印
fily1314
Rank: 1
等级:新手上路
帖子:24
积分:366
注册:2007-7-18
哪位大大帮忙改进下这个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 System.IO

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 System.IO.MemoryStream()

        '使用 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 System.IO.MemoryStream()

        '使用 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
2008-6-27 17:15
共有 376 人关注过本帖
发新话题
关于我们 | 广告合作 | 编程中国 | 清除Cookies | Archiver | WAP | TOP

编程中国 版权所有,并保留所有权利。鲁ICP备08000592号
Powered by Discuz, Processed in 0.060866 second(s), 9 queries.
Copyright©2004-2008, BCCN.NET, All Rights Reserved