I've problem with Rijndael PKCS7

Discussion in 'ASP .Net Security' started by Yuna84, Apr 16, 2004.

  1. Yuna84

    Yuna84 Guest

    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???
     
    Yuna84, Apr 16, 2004
    #1
    1. Advertising

  2. I suggest you to take a look at the sample in
    http://sourceforge.net/projects/ncrypto/
    You will find a good sample in CryptoHelper.Encrypt or Decrypt methods.

    In your sample, I notice the different encoding methods when encrypting and
    decrypting and the algorithm usage is not very "clean" (Close() the alg
    instance when finishing) nor readable.


    Hernan de Lahitte
    Lagash Systems S.A.
    http://weblogs.asp.net/hernandl


    This posting is provided "AS IS" with no warranties, and confers no rights.

    "Yuna84" <> wrote in message
    news:...
    > 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???
     
    Hernan de Lahitte, Apr 16, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Gilles Lenfant

    PKCS7 file signature checking.

    Gilles Lenfant, Sep 3, 2003, in forum: Python
    Replies:
    0
    Views:
    445
    Gilles Lenfant
    Sep 3, 2003
  2. Ignacio De Marco

    Problems implementing Rijndael

    Ignacio De Marco, Sep 2, 2004, in forum: C Programming
    Replies:
    3
    Views:
    411
    Stephen Sprunk
    Sep 8, 2004
  3. Thomas Guettler

    crypto: verify external pkcs7 signature

    Thomas Guettler, Mar 24, 2010, in forum: Python
    Replies:
    0
    Views:
    941
    Thomas Guettler
    Mar 24, 2010
  4. hivie

    Length of data to decrypt is invalid Rijndael

    hivie, Jun 13, 2005, in forum: ASP .Net Security
    Replies:
    2
    Views:
    554
    Duane Laflotte
    Jun 13, 2005
  5. snacktime
    Replies:
    0
    Views:
    202
    snacktime
    Aug 30, 2006
Loading...

Share This Page