Click here to Skip to main content
15,881,741 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: Problem with DataGridView Pin
Christian Graus9-Jun-09 17:13
protectorChristian Graus9-Jun-09 17:13 
QuestionCouple questions regarding binding a datagridviewcolumn to an auto increment database column Pin
Jon_Boy9-Jun-09 8:39
Jon_Boy9-Jun-09 8:39 
AnswerRe: Couple questions regarding binding a datagridviewcolumn to an auto increment database column Pin
Johan Hakkesteegt9-Jun-09 22:10
Johan Hakkesteegt9-Jun-09 22:10 
AnswerRe: Couple questions regarding binding a datagridviewcolumn to an auto increment database column Pin
Jon_Boy11-Jun-09 9:09
Jon_Boy11-Jun-09 9:09 
QuestionHow read a url from xml and open a tab in the webrowser? Pin
Dynamic12349-Jun-09 7:02
Dynamic12349-Jun-09 7:02 
AnswerRe: How read a url from xml and open a tab in the webrowser? Pin
Christian Graus9-Jun-09 10:50
protectorChristian Graus9-Jun-09 10:50 
GeneralRe: How read a url from xml and open a tab in the webrowser? Pin
Dynamic12349-Jun-09 22:32
Dynamic12349-Jun-09 22:32 
QuestionPadding is invalid and cannot be removed Pin
Raheem MA9-Jun-09 4:00
Raheem MA9-Jun-09 4:00 
Hi friends,

We are getting the following error while trying to decrypt the string which is encrypted using the same class.

"Padding is invalid and cannot be removed"

following is the class: (VB.NET)

Imports System
Imports System.IO
Imports System.Security.Cryptography

Public Class EncryptDecrypt
Dim key() As Byte
Dim iv() As Byte
Dim firstRJ As RijndaelManaged

Sub EncryptDecrypt()
Me.InitializeKeyIV()
End Sub

Sub InitializeKeyIV()
key = New Byte() {229, 249, 126, 70, 196, 148, 231, 10, 130, 22, 65, 172, 216, 13, 68, 234, 46, 146, 31, 102, 228, 181, 212, 145}
iv = New Byte() {8, 14, 130, 251, 155, 125, 219, 144, 103, 182, 95, 103, 58, 6, 205, 161}
End Sub

Public Function Encrypt(ByVal clearText) As String
Dim retChiperText As String = ""

If clearText <> "" Then
Dim ms As MemoryStream = Nothing
Dim cs As CryptoStream = Nothing
Dim sw As StreamWriter = Nothing

Try
ms = New MemoryStream()
firstRJ = New RijndaelManaged()
Dim encryptor As ICryptoTransform = firstRJ.CreateEncryptor(key, iv)
cs = New CryptoStream(ms, encryptor, CryptoStreamMode.Write)
sw = New StreamWriter(cs)
sw.Write(clearText)
sw.Close()
Dim chiperTextBytes As Byte()
chiperTextBytes = ms.ToArray()
retChiperText = Convert.ToBase64String(chiperTextBytes)
Catch Ex As Exception

Finally
cs.Close()
ms.Close()
firstRJ.Clear()
End Try
End If
Encrypt = retChiperText
End Function

Public Function Decrypt(ByVal chiperText) As String
Dim retClearText As String = ""
chiperText = Trim(chiperText)
MessageBox.Show("Text: " + chiperText)
If chiperText <> "" Then
Dim cs2 As CryptoStream = Nothing
Dim ms2 As MemoryStream = Nothing
Dim sr As StreamReader = Nothing

Try
Dim chText As Byte()
chText = Convert.FromBase64String(chiperText)
firstRJ = New RijndaelManaged()
ms2 = New MemoryStream(chText)
Dim decryptor As ICryptoTransform = firstRJ.CreateDecryptor(key, iv)
cs2 = New CryptoStream(ms2, decryptor, CryptoStreamMode.Read)
sr = New StreamReader(cs2)
retClearText = sr.ReadLine()
sr.Close()
Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
cs2.Flush()
cs2.Close()
ms2.Close()
firstRJ.Clear()
'secRJ.Clear()
End Try
End If
Decrypt = retClearText
End Function

End Class

If we instantiate this class in another class the try to decrypt the value, we are getting the above error. Otherwise, if we try to use the decrypt function from the same class it is working fine.

Any ideas on this issue?

Smile | :) Thank you in advance Smile | :)
AnswerRe: Padding is invalid and cannot be removed Pin
Dave Kreskowiak10-Jun-09 1:59
mveDave Kreskowiak10-Jun-09 1:59 
QuestionVB6.0 with Registered OCX control Pin
vhassan9-Jun-09 2:55
vhassan9-Jun-09 2:55 
AnswerRe: VB6.0 with Registered OCX control Pin
Dave Kreskowiak9-Jun-09 6:32
mveDave Kreskowiak9-Jun-09 6:32 
GeneralRe: VB6.0 with Registered OCX control Pin
vhassan9-Jun-09 19:16
vhassan9-Jun-09 19:16 
GeneralRe: VB6.0 with Registered OCX control Pin
Dave Kreskowiak10-Jun-09 1:57
mveDave Kreskowiak10-Jun-09 1:57 
AnswerRe: VB6.0 with Registered OCX control Pin
Jon_Boy9-Jun-09 7:58
Jon_Boy9-Jun-09 7:58 
QuestionProblem with restarting thread Pin
sohaib_a9-Jun-09 2:49
sohaib_a9-Jun-09 2:49 
AnswerRe: Problem with restarting thread Pin
Johan Hakkesteegt9-Jun-09 3:12
Johan Hakkesteegt9-Jun-09 3:12 
AnswerRe: Problem with restarting thread Pin
LCARS x329-Jun-09 22:43
LCARS x329-Jun-09 22:43 
QuestionReading application .config file Pin
WorkingAcc9-Jun-09 2:36
WorkingAcc9-Jun-09 2:36 
AnswerRe: Reading application .config file Pin
Dave Kreskowiak9-Jun-09 6:28
mveDave Kreskowiak9-Jun-09 6:28 
GeneralRe: Reading application .config file Pin
WorkingAcc10-Jun-09 20:18
WorkingAcc10-Jun-09 20:18 
GeneralRe: Reading application .config file Pin
Dave Kreskowiak11-Jun-09 1:44
mveDave Kreskowiak11-Jun-09 1:44 
GeneralRe: Reading application .config file Pin
WorkingAcc11-Jun-09 1:52
WorkingAcc11-Jun-09 1:52 
QuestionHow can I bring a rare picture format to a picture box? Pin
Sonhospa9-Jun-09 2:16
Sonhospa9-Jun-09 2:16 
AnswerRe: How can I bring a rare picture format to a picture box? Pin
Nagy Vilmos9-Jun-09 2:29
professionalNagy Vilmos9-Jun-09 2:29 
QuestionRe: How can I bring a rare picture format to a picture box? Pin
Sonhospa9-Jun-09 3:03
Sonhospa9-Jun-09 3:03 

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.