Click here to Skip to main content
12,996,511 members (67,292 online)

Visual Basic

 
QuestionRijndael encryption not working Pin
maskrtnik0114-Nov-12 2:20
membermaskrtnik0114-Nov-12 2:20 
AnswerRe: Rijndael encryption not working Pin
Keith Barrow14-Nov-12 2:52
mentorKeith Barrow14-Nov-12 2:52 
GeneralRe: Rijndael encryption not working Pin
maskrtnik0114-Nov-12 3:08
membermaskrtnik0114-Nov-12 3:08 
GeneralRe: Rijndael encryption not working Pin
Keith Barrow14-Nov-12 3:26
mentorKeith Barrow14-Nov-12 3:26 
GeneralRe: Rijndael encryption not working Pin
Keith Barrow14-Nov-12 3:35
mentorKeith Barrow14-Nov-12 3:35 
GeneralRe: Rijndael encryption not working Pin
maskrtnik0114-Nov-12 3:48
membermaskrtnik0114-Nov-12 3:48 
GeneralRe: Rijndael encryption not working Pin
Keith Barrow14-Nov-12 4:05
mentorKeith Barrow14-Nov-12 4:05 
QuestionRe: Rijndael encryption not working Pin
maskrtnik0115-Nov-12 19:40
membermaskrtnik0115-Nov-12 19:40 
Maybe it is stable now. But there is new problem. I have tried decrypting encrypted file, but it fails to decrypt, decrypted data absolutely do not match data which was encrypted. I am using this code:
Public Sub Save(ByVal carrier As DataCarrier, ByVal password As String, ByVal filename As String)
        Try
            Using sha As New SHA512Managed
                Dim hash = sha.ComputeHash(Encoding.Default.GetBytes(password))
                Dim key As Byte() = New Byte(31) {}
                Dim iv As Byte() = New Byte(15) {}
                Array.Copy(hash, 0, key, 0, 32)
                Array.Copy(hash, 32, iv, 0, 16)
                Using aes As New RijndaelManaged, filestr As New FileStream(filename, FileMode.Create, FileAccess.Write)
                    Using cryptostr As New CryptoStream(filestr, aes.CreateEncryptor(key, iv), CryptoStreamMode.Write)
                        ExportData(carrier).Save(cryptostr)
                    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
    Public Function Load(ByVal password As String, ByVal filename As String) As XDocument
        Dim sha As SHA512Managed
        Dim aes As RijndaelManaged
        Dim trans As ICryptoTransform
        Dim cryptostr As CryptoStream
        Dim filestr As FileStream
        Try
            sha = New SHA512Managed()
            Dim hash = sha.ComputeHash(Encoding.Default.GetBytes(password))
            aes = New RijndaelManaged()
            Dim key As Byte() = New Byte(31) {}
            Dim iv As Byte() = New Byte(15) {}
            Array.Copy(hash, 0, key, 0, 32)
            Array.Copy(hash, 32, iv, 0, 16)
            trans = aes.CreateEncryptor(key, iv)
            filestr = New FileStream(filename, FileMode.Open)
            cryptostr = New CryptoStream(filestr, trans, CryptoStreamMode.Read)
            Return XDocument.Load(cryptostr)
        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)
        Finally
            If cryptostr IsNot Nothing Then cryptostr.Dispose()
            If filestr IsNot Nothing Then filestr.Dispose()
            If trans IsNot Nothing Then trans.Dispose()
            If aes IsNot Nothing Then aes.Dispose()
            If sha IsNot Nothing Then sha.Dispose()
        End Try
    End Function


modified 17-Nov-12 11:23am.

GeneralRe: Rijndael encryption not working Pin
DisIsHoody14-Nov-12 9:34
memberDisIsHoody14-Nov-12 9:34 
GeneralRe: Rijndael encryption not working Pin
maskrtnik0114-Nov-12 18:21
membermaskrtnik0114-Nov-12 18:21 
AnswerRe: Rijndael encryption not working Pin
DisIsHoody15-Nov-12 17:37
memberDisIsHoody15-Nov-12 17:37 
GeneralRe: Rijndael encryption not working Pin
maskrtnik0115-Nov-12 19:37
membermaskrtnik0115-Nov-12 19:37 
QuestionRetrive date from sql server in system date format in VB6 application by a one time setting Pin
Johnson Antony13-Nov-12 13:34
memberJohnson Antony13-Nov-12 13:34 
AnswerRe: Retrive date from sql server in system date format in VB6 application by a one time setting Pin
Dave Kreskowiak13-Nov-12 14:00
mvpDave Kreskowiak13-Nov-12 14:00 
QuestionHow to find out if a file is in use before reading the data in that file Pin
KreativeKai13-Nov-12 7:47
memberKreativeKai13-Nov-12 7:47 
AnswerRe: How to find out if a file is in use before reading the data in that file Pin
Dave Kreskowiak13-Nov-12 8:09
mvpDave Kreskowiak13-Nov-12 8:09 
GeneralRe: How to find out if a file is in use before reading the data in that file Pin
KreativeKai13-Nov-12 8:22
memberKreativeKai13-Nov-12 8:22 
GeneralRe: How to find out if a file is in use before reading the data in that file Pin
KreativeKai13-Nov-12 8:46
memberKreativeKai13-Nov-12 8:46 
AnswerRe: How to find out if a file is in use before reading the data in that file Pin
KreativeKai13-Nov-12 8:13
memberKreativeKai13-Nov-12 8:13 
GeneralRe: How to find out if a file is in use before reading the data in that file Pin
Dave Kreskowiak13-Nov-12 9:57
mvpDave Kreskowiak13-Nov-12 9:57 
AnswerRe: How to find out if a file is in use before reading the data in that file Pin
Eddy Vluggen13-Nov-12 11:41
memberEddy Vluggen13-Nov-12 11:41 
GeneralRe: How to find out if a file is in use before reading the data in that file Pin
KreativeKai14-Nov-12 1:37
memberKreativeKai14-Nov-12 1:37 
GeneralRe: How to find out if a file is in use before reading the data in that file Pin
VitorHugoGarcia19-Nov-12 1:12
memberVitorHugoGarcia19-Nov-12 1:12 
QuestionVB Script for automatically turning off the monitor Pin
Prasan Cumar13-Nov-12 4:14
memberPrasan Cumar13-Nov-12 4:14 
AnswerRe: VB Script for automatically turning off the monitor Pin
Dave Kreskowiak13-Nov-12 4:59
mvpDave Kreskowiak13-Nov-12 4:59 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    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.170609.2 | Last Updated 20 Jun 2017
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid