Click here to Skip to main content
       

Visual Basic

 
AnswerRe: Changing Assembly Properties through Reflection PinmemberEddy Vluggen15-Nov-12 1:18 
GeneralRe: Changing Assembly Properties through Reflection PinmemberDisIsHoody15-Nov-12 17:14 
GeneralRe: Changing Assembly Properties through Reflection PinmemberEddy Vluggen16-Nov-12 0:06 
Questionmessagebeep PinmemberGil Goodridge14-Nov-12 8:00 
AnswerRe: messagebeep PinmvpDave Kreskowiak14-Nov-12 8:31 
QuestionRijndael encryption not working Pinmembermaskrtnik0114-Nov-12 2:20 
AnswerRe: Rijndael encryption not working PinmentorKeith Barrow14-Nov-12 2:52 
GeneralRe: Rijndael encryption not working Pinmembermaskrtnik0114-Nov-12 3:08 
It does not throw any exception.
 
ExportData method only creates XML document with data to be encrypted. I have checked, that result of ExportData contains, what it should cotain.
 
I have also tried following, again, empty file is generated.
Public Sub Save(ByVal carrier As DataCarrier, ByVal password As String, ByVal filename As String)
            Try
                Using sha As New SHA512Managed
                    Dim salt As Byte() = sha.ComputeHash(Encoding.Default.GetBytes(password))
                    Using pdb As New Rfc2898DeriveBytes(password, salt), aes As New RijndaelManaged, filestr As New FileStream(filename, FileMode.Create, FileAccess.Write)
                        Using cryptostr As New CryptoStream(filestr, aes.CreateEncryptor(pdb.GetBytes(32), pdb.GetBytes(16)), CryptoStreamMode.Write)
                            Dim str = ExportData(carrier).ToString()
                            Using w As New StreamWriter(cryptostr)
                                w.Write(str)
                            End Using
                        End Using
                    End Using
                End Using
            Catch ex As Exception
                Logging.Instance.WriteException(ex, TraceEventType.Error)
                MessageBox.Show(String.Format(My.Resources.UnhandledExceptionExString, ex.Message, ex.ToString), My.Application.Info.Title, MessageBoxButtons.OK, MessageBoxIcon.Error)
            End Try
        End Sub
 
Moreover, I have tried simply writing string literal to CryptoStream, this approach generates empty file too.
 
Strange is, that when I run this version:
 Public Sub Save(ByVal carrier As DataCarrier, ByVal password As String, ByVal filename As String)
            Try
                Using sha As New SHA512Managed
                    Dim salt As Byte() = sha.ComputeHash(Encoding.Default.GetBytes(password))
                    Using pdb As New Rfc2898DeriveBytes(password, salt), aes As New RijndaelManaged, filestr As New MemoryStream() 'filestr As New FileStream(filename, FileMode.Create, FileAccess.Write)
                        Using cryptostr As New CryptoStream(filestr, aes.CreateEncryptor(pdb.GetBytes(32), pdb.GetBytes(16)), CryptoStreamMode.Write)
                            ExportData(carrier).Save(cryptostr)
                            Dim str = New String(Encoding.Default.GetChars(filestr.ToArray()))
                            Debugger.Break()
                        End Using
                    End Using
                End Using
            Catch ex As Exception
                Logging.Instance.WriteException(ex, TraceEventType.Error)
                MessageBox.Show(String.Format(My.Resources.UnhandledExceptionExString, ex.Message, ex.ToString), My.Application.Info.Title, MessageBoxButtons.OK, MessageBoxIcon.Error)
            End Try
        End Sub
Then at Debugger.Break statement str variable cotains data, which should be in the file.
 
While this and simmilar solutions generate empty file.
Public Sub Save(ByVal carrier As DataCarrier, ByVal password As String, ByVal filename As String)
            Try
                Using sha As New SHA512Managed
                    Dim salt As Byte() = sha.ComputeHash(Encoding.Default.GetBytes(password))
                    Using pdb As New Rfc2898DeriveBytes(password, salt), aes As New RijndaelManaged, filestr As New MemoryStream() 'filestr As New FileStream(filename, FileMode.Create, FileAccess.Write)
                        Using cryptostr As New CryptoStream(filestr, aes.CreateEncryptor(pdb.GetBytes(32), pdb.GetBytes(16)), CryptoStreamMode.Write)
                            ExportData(carrier).Save(cryptostr)
                            File.WriteAllBytes(filename, filestr.ToArray())
                            Debugger.Break()
                        End Using
                    End Using
                End Using
            Catch ex As Exception
                Logging.Instance.WriteException(ex, TraceEventType.Error)
                MessageBox.Show(String.Format(My.Resources.UnhandledExceptionExString, ex.Message, ex.ToString), My.Application.Info.Title, MessageBoxButtons.OK, MessageBoxIcon.Error)
            End Try
        End Sub
 
I am really confused on what it does.
GeneralRe: Rijndael encryption not working PinmentorKeith Barrow14-Nov-12 3:26 
GeneralRe: Rijndael encryption not working PinmentorKeith Barrow14-Nov-12 3:35 
GeneralRe: Rijndael encryption not working Pinmembermaskrtnik0114-Nov-12 3:48 
GeneralRe: Rijndael encryption not working PinmentorKeith Barrow14-Nov-12 4:05 
QuestionRe: Rijndael encryption not working [modified] Pinmembermaskrtnik0115-Nov-12 19:40 
GeneralRe: Rijndael encryption not working PinmemberDisIsHoody14-Nov-12 9:34 
GeneralRe: Rijndael encryption not working Pinmembermaskrtnik0114-Nov-12 18:21 
AnswerRe: Rijndael encryption not working PinmemberDisIsHoody15-Nov-12 17:37 
GeneralRe: Rijndael encryption not working Pinmembermaskrtnik0115-Nov-12 19:37 
QuestionRetrive date from sql server in system date format in VB6 application by a one time setting PinmemberJohnson Antony13-Nov-12 13:34 
AnswerRe: Retrive date from sql server in system date format in VB6 application by a one time setting PinmvpDave Kreskowiak13-Nov-12 14:00 
QuestionHow to find out if a file is in use before reading the data in that file PinmemberKreativeKai13-Nov-12 7:47 
AnswerRe: How to find out if a file is in use before reading the data in that file PinmvpDave Kreskowiak13-Nov-12 8:09 
GeneralRe: How to find out if a file is in use before reading the data in that file PinmemberKreativeKai13-Nov-12 8:22 
GeneralRe: How to find out if a file is in use before reading the data in that file PinmemberKreativeKai13-Nov-12 8:46 
AnswerRe: How to find out if a file is in use before reading the data in that file PinmemberKreativeKai13-Nov-12 8:13 
GeneralRe: How to find out if a file is in use before reading the data in that file [modified] PinmvpDave Kreskowiak13-Nov-12 9:57 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.


Advertise | Privacy | Mobile
Web02 | 2.8.141015.1 | Last Updated 21 Oct 2014
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid