| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1675 人关注过本帖
标题:哪位大大帮忙改进下这个DES加密解密函数
只看楼主 加入收藏
fily1314
Rank: 9Rank: 9Rank: 9
等 级:蜘蛛侠
帖 子:166
专家分:1190
注 册:2007-7-18
结帖率:75%
收藏
 问题点数:0 回复次数:0 
哪位大大帮忙改进下这个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
搜索更多相关主题的帖子: DES 函数 Intel 双核 内存 
2008-06-27 17:15
快速回复:哪位大大帮忙改进下这个DES加密解密函数
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.014465 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved