I've problem with Rijndael PKCS7

Ask a Question related to ASP.NET Security, Design and Development.

  1. #1

    Default I've problem with Rijndael PKCS7

    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:
    [url]http://www.dotnethell.it/articles/article.aspx?ArticleID=93[/url]

    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 Guest

  2. Similar Questions and Discussions

    1. contribute problem - access denied file may not existpermission problem
      Recieving the following error message - "access denied file may not exist , or there could be a permission problem" this happened this morning ,...
    2. Problem playing Quicktime thru .DCR embedded in HTML - pathreferencing problem?
      Greetings earthlings and Director heads. Here's the problem: created an HTML file containing shockwave (dcr) movie that calls quicktime movies in...
    3. Uploading problem = weird warning (was: access denied problem.....)
      Hi, I had a problem where my upload form was not working on our production server but was working on two other servers, after checking the...
    4. #21611 [Opn]: Problem with version_compare() (Was: Problem with pear cli and release numbers)
      ID: 21611 Updated by: et@php.net -Summary: Problem with pear cli and release numbers Reported By: jan at horde...
    5. Problem with Apache Web Server config file and PHP (please give advice on what problem may be me)
      HI: Can anyone refer me to someone that can help with the problem below. I installed Apache Web Server on my laptop which has Windows XP. I...
  3. #2

    Default Re: I've problem with Rijndael PKCS7

    I suggest you to take a look at the sample in
    [url]http://sourceforge.net/projects/ncrypto/[/url]
    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.
    [url]http://weblogs.asp.net/hernandl[/url]


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

    "Yuna84" <acquargento@yahoo.it> wrote in message
    news:48144a5.0404160511.38097908@posting.google.co m...
    > 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:
    > [url]http://www.dotnethell.it/articles/article.aspx?ArticleID=93[/url]
    >
    > 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 Guest

  4. #3

    Default Re: I've problem with Rijndael PKCS7

    Sometimes the problem is with an altered encrypted string. I found this out when I was trying to decrypt a string I had inadvertently changed to lower case.

    ---
    Posted using Wimdows.net NntpNews Component -

    Post Made from [url]http://www.DotNetJunkies.com/newsgroups[/url] Our newsgroup engine supports Post Alerts, Ratings, and Searching.
    DotNetJunkies User Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139