DOBON.NETお気楽掲示板

[ 最新記事及び返信フォームをトピックトップへ ]

■1559 / inTopicNo.1)  パスワードで文字列を暗号化する
  
□投稿者/ おるは -(2015/01/14(Wed) 17:18:04)
  • アイコンお願いします。

    復号化したバイト型に代入されているbsを文字列に変換し出力すると2回目以降、止まってしまいます。
    追加した部分でおかしいような感じはしないのですが。
    よろしくお願いいたします。

    Public Function DecryptFile(ByVal sourceFile As String, _
    ByVal destFile As String, _
    ByVal key As Byte(), _
    ByVal iv As Byte()) As String
    'RijndaelManagedオブジェクトの作成
    Dim rijndael As New System.Security.Cryptography.RijndaelManaged()

    '共有キーと初期化ベクタを設定
    rijndael.Key = key
    rijndael.IV = iv

    '暗号化されたファイルを読み込むためのFileStream
    Dim inFs As New System.IO.FileStream( _
    sourceFile, System.IO.FileMode.Open, System.IO.FileAccess.Read)
    '対称復号化オブジェクトの作成
    Dim decryptor As System.Security.Cryptography.ICryptoTransform = _
    rijndael.CreateDecryptor()
    '暗号化されたデータを読み込むためのCryptoStreamの作成
    Dim cryptStrm As New System.Security.Cryptography.CryptoStream( _
    inFs, decryptor, System.Security.Cryptography.CryptoStreamMode.Read)

    '復号化されたデータを書き出す
    Dim outFs As New System.IO.FileStream( _
    destFile, System.IO.FileMode.Create, System.IO.FileAccess.Write)
    Dim bs As Byte() = New Byte(1023) {}
    Dim readLen As Integer
    While True
    '復号化に失敗すると例外CryptographicExceptionが発生
    readLen = cryptStrm.Read(bs, 0, bs.Length)
    If readLen = 0 Then
    Exit While
    End If
    outFs.Write(bs, 0, readLen)
    End While

    ---追加した部分--------------------------
    Dim DecryptStr As String
    'Shift JISとして文字列に変換
    DecryptStr = System.Text.Encoding.GetEncoding(932).GetString(bs)
    Console.WriteLine(DecryptStr) 
    -----------------------------------------

    '閉じる
    outFs.Close() ←ココで止まる
    cryptStrm.Close()
    decryptor.Dispose()
    inFs.Close()


引用返信 削除キー/



トピック内ページ移動 / << 0 >>

このトピックに書きこむ

Pass/


- Child Tree -