0

ファイルを保存しようとしていますが、暗号化して一時的な暗号化されていないファイルを削除します。これは私の暗号化サブです。エラー行は最後の行に発生します。

Sub EncryptFile(ByVal sInputFilename As String, _
              ByVal sOutputFilename As String, _
              ByVal sKey As String)

    Dim fsInput As New FileStream(sInputFilename, _
                                FileMode.Open, FileAccess.Read)
    Dim fsEncrypted As New FileStream(sOutputFilename, _
                                FileMode.Create, FileAccess.Write)

    Dim DES As New DESCryptoServiceProvider()

    'Set secret key for DES algorithm.
    'A 64-bit key and an IV are required for this provider.
    DES.Key = ASCIIEncoding.ASCII.GetBytes(sKey)

    'Set the initialization vector.
    DES.IV = ASCIIEncoding.ASCII.GetBytes(sKey)

    'Create the DES encryptor from this instance.
    Dim desencrypt As ICryptoTransform = DES.CreateEncryptor()
    'Create the crypto stream that transforms the file stream by using DES encryption.
    Dim cryptostream As New CryptoStream(fsEncrypted, _
                                        desencrypt, _
                                        CryptoStreamMode.Write)

    'Read the file text to the byte array.
    Dim bytearrayinput(fsInput.Length - 1) As Byte
    fsInput.Read(bytearrayinput, 0, bytearrayinput.Length)
    'Write out the DES encrypted file.
    cryptostream.Write(bytearrayinput, 0, bytearrayinput.Length)
    cryptostream.Close()
    System.IO.File.Delete(sInputFilename)
End Sub

誰でもこれで私を助けることができますか? 何が間違っているのかわかりません。

4

1 に答える 1

0

fsInput.Close()直前に使用System.IO.File.Delete(sInputFilename)

お役に立てれば

于 2013-04-13T17:15:10.710 に答える