This is dot net 1.1
Also get the same error in VS2005
Code:
Private Sub btDecrypt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btDecrypt.Click
Dim crypto As New System.Security.Cryptography.RijndaelManaged
Dim encryptedData As Byte() = FromHex("f9ef77d27b8fed0f088963be7d3e2f15")
crypto.Key = FromHex("265670755823513b6d54423c79536560")
crypto.IV = New Byte(encryptedData.Length - 1) {}
Dim encryptedMemStream As New System.IO.MemoryStream(encryptedData, 0, encryptedData.Length)
Dim b() As Byte = New Byte(encryptedData.Length - 1) {}
Dim cs As New System.Security.Cryptography.CryptoStream(encryptedMemStream, crypto.CreateDecryptor(), System.Security.Cryptography.CryptoStreamMode.Read)
Try
cs.Read(b, 0, encryptedData.Length - 1)
Catch ex As System.Security.Cryptography.CryptographicException
Throw New System.Security.Cryptography.CryptographicException("Unable to decrypt data. The provided key may be invalid.", ex)
Finally
cs.Close()
End Try
tbEncryptResult.Text = ToHex(b)
End Sub
Shared Function ToHex(ByVal ba() As Byte) As String
If ba Is Nothing OrElse ba.Length = 0 Then
Return ""
End If
Const HexFormat As String = "{0:X2}"
Dim sb As New System.Text.StringBuilder
For Each b As Byte In ba
sb.Append(String.Format(HexFormat, b))
Next
Return sb.ToString
End Function
Shared Function FromHex(ByVal hexEncoded As String) As Byte()
If hexEncoded Is Nothing OrElse hexEncoded.Length = 0 Then
Return Nothing
End If
Try
Dim l As Integer = Convert.ToInt32(hexEncoded.Length / 2)
Dim b(l - 1) As Byte
For i As Integer = 0 To l - 1
b(i) = Convert.ToByte(hexEncoded.Substring(i * 2, 2), 16)
Next
Return b
Catch ex As Exception
Throw New System.FormatException("The provided string does not appear to be Hex encoded:" & _
Environment.NewLine & hexEncoded & Environment.NewLine, ex)
End Try
End Function
Are we sure that this is indeed a valid key / encrypted pair?