Y
Yuna84
I've tried with a simple program in vb.net but when i'm going to
decript in my messagebox appears this message: PKCS7 padding is
invalid and cannot be removed.
I've found this few lines of codes in this site:
http://www.dotnethell.it/articles/article.aspx?ArticleID=93
I've trasform in vb.net and this is the result
Imports system.security.cryptography
imports system.text
('I don't write the other normal imports)
Public Function Encode(ByVal s As String, ByVal chiave As String,
ByVal IV As String) As String
Dim ascii As New ASCIIEncoding
Dim rjm As New RijndaelManaged
rjm.KeySize = 128
rjm.BlockSize = 128
rjm.Key = ascii.GetBytes(chiave)
rjm.Key = ascii.GetBytes(IV)
Dim input() As Byte = Encoding.UTF7.GetBytes(s)
Dim output() As Byte =
rjm.CreateEncryptor().TransformFinalBlock(input, 0, input.Length)
Return Convert.ToBase64String(output)
End Function
Public Function Decode(ByVal s As String, ByVal chiave As String,
ByVal IV As String) As String
Dim rjm As New RijndaelManaged
Dim ascii As New ASCIIEncoding
rjm.KeySize = 128
rjm.BlockSize = 128
rjm.Key = ascii.GetBytes(chiave)
rjm.Key = ascii.GetBytes(IV)
Try
Dim input() As Byte = Convert.FromBase64String(s)
Dim output() As Byte =
rjm.CreateDecryptor().TransformFinalBlock(input, 0, input.Length)
Return Encoding.UTF7.GetString(output)
Catch e As Exception
MessageBox.Show(e.Message & " " & e.Source)
End Try
End Function
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Button1.Click
txtDecripta.Text = (Encode(txtCripta.Text, "AsDfGhJkLqPwOeIr",
"RiEoWpQlKjHgFdSa"))
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Button2.Click
Console.WriteLine(Decode(txtDecripta.Text, "AsDfGhJkLqPwOeIr",
"RiEoWpQlKjHgFdSa"))
End Sub
Please. This is an emergency!!!! Can you help me???
decript in my messagebox appears this message: PKCS7 padding is
invalid and cannot be removed.
I've found this few lines of codes in this site:
http://www.dotnethell.it/articles/article.aspx?ArticleID=93
I've trasform in vb.net and this is the result
Imports system.security.cryptography
imports system.text
('I don't write the other normal imports)
Public Function Encode(ByVal s As String, ByVal chiave As String,
ByVal IV As String) As String
Dim ascii As New ASCIIEncoding
Dim rjm As New RijndaelManaged
rjm.KeySize = 128
rjm.BlockSize = 128
rjm.Key = ascii.GetBytes(chiave)
rjm.Key = ascii.GetBytes(IV)
Dim input() As Byte = Encoding.UTF7.GetBytes(s)
Dim output() As Byte =
rjm.CreateEncryptor().TransformFinalBlock(input, 0, input.Length)
Return Convert.ToBase64String(output)
End Function
Public Function Decode(ByVal s As String, ByVal chiave As String,
ByVal IV As String) As String
Dim rjm As New RijndaelManaged
Dim ascii As New ASCIIEncoding
rjm.KeySize = 128
rjm.BlockSize = 128
rjm.Key = ascii.GetBytes(chiave)
rjm.Key = ascii.GetBytes(IV)
Try
Dim input() As Byte = Convert.FromBase64String(s)
Dim output() As Byte =
rjm.CreateDecryptor().TransformFinalBlock(input, 0, input.Length)
Return Encoding.UTF7.GetString(output)
Catch e As Exception
MessageBox.Show(e.Message & " " & e.Source)
End Try
End Function
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Button1.Click
txtDecripta.Text = (Encode(txtCripta.Text, "AsDfGhJkLqPwOeIr",
"RiEoWpQlKjHgFdSa"))
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Button2.Click
Console.WriteLine(Decode(txtDecripta.Text, "AsDfGhJkLqPwOeIr",
"RiEoWpQlKjHgFdSa"))
End Sub
Please. This is an emergency!!!! Can you help me???