none
vb.net 用异或方法加密zip打包的上百兆的文件,时间很慢 有没有什么方法 RRS feed

  • 问题

  •  Public Function copyAndEncryptFile(ByVal oldPath As String, ByVal newPath As String, ByVal key As String) As String
            Try
                Dim fs As System.IO.FileStream
                fs = New System.IO.FileStream(oldPath, FileMode.Open, FileAccess.Read) '得到本地文件的数据流
                Dim s As System.IO.FileStream
                s = New System.IO.FileStream(newPath, FileMode.Create, FileAccess.Write) '得到本地文件的数据流
                Dim b(fs.Length) As Byte
     
                Dim n As Integer
                Dim count As Integer = 0
                'Dim startPos As Integer = 0
     
                n = fs.Read(b, 0, b.Length)
                'Dim aa() As Byte = xorString(b, key)
                's.Write(b, 0, n)
                Do While n > 0
                    Dim aa() As Byte = xorString(b, key)
     
                    s.Write(aa, 0, n)
                    n = fs.Read(b, 0, b.Length)
                    count += 1
                Loop
                fs.Close()
                s.Close()
                GC.Collect()
            Catch ex As Exception
                Throw ex
            End Try
        End Function
        Public Function xorString(ByVal b() As Byte, ByVal key As String) As Byte()
            For i As Integer = 0 To b.Length - 1
                b(i) = b(i) Xor key
            Next
            Return b
        End Function
    2009年5月13日 7:51

答案

  • 建议使用MemoryStream缓存读写过程以提高性能

    ***** 向着两颗奖牌出发!~~~ ^_^ *****
    ***** 本人目前处于努力学习模式,希望大家多多伸手帮助~ *****
    2009年5月13日 11:56