I am working on program to be used to process confidential data. That data must be well-encrypted. I have built method, that exports data from memory to XML, encrypts XMl document and saves it to file. But, what seems strange to me is, that encryption method doesn’t work. After its execution, file, which may contain encrypted data is created, but remains empty. I don’ t see any bug in the code. Could you help me to get it working, please?
Here is code used to encrypt and save XML.
Public Sub Save(ByVal carrier As DataCarrier, ByVal password As String, ByVal filename As String)
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)
Catch ex As Exception
MessageBox.Show(String.Format(My.Resources.UnhandledExceptionExString, ex.Message, ex.ToString), My.Application.Info.Title, MessageBoxButtons.OK, MessageBoxIcon.Error)
Also, is that encryption algorithm OK, or there is some way to break it? I must be sure that there is no way to break encryption, that is used.