Invalid character in a Base-64 string

Discussion in 'ASP .Net' started by =?Utf-8?B?SmFtZXM=?=, Apr 23, 2007.

  1. I'm trying to encrypt a part of a url as follows:

    test.aspx?id=123&check=abc

    Basically, I'm using TripleDes encryption to encrypt the id, then include
    this as check in the url to prevent tampering. I'm working from some code
    from http://www.15seconds.com/Issue/021210.htm

    It seems to work fine except a few seem to through up problems as follows:

    Invalid character in a Base-64 string

    Line 83:
    Line 84: 'convert from string to byte array
    Line 85: Dim buffer As Byte() = Convert.FromBase64String(value)
    Line 86: Dim ms As MemoryStream = New MemoryStream(buffer)
    Line 87: Dim cs As CryptoStream = New CryptoStream(ms,
    cryptoProvider.CreateDecryptor(KEY_192, IV_192), CryptoStreamMode.Read)


    An example ID that throws up a problem is 1026 which gives the check
    eIn9iD3i+JE=

    I'm guessing it is to do with the + sign, but even when urlencoded it gives
    the same error.

    I can post more code if needed... but any advice would be great. Is there a
    better / more reliable way to encrypt?

    Cheers
     
    =?Utf-8?B?SmFtZXM=?=, Apr 23, 2007
    #1
    1. Advertising

  2. =?Utf-8?B?SmFtZXM=?=

    bruce barker Guest

    the + decodes to a space (as spaces are not allowed in a url).
    urlencoding leaves it alone. you will need manually convert it to "%2b"
    after performing a urlencode.

    -- bruce (sqlwork.com)

    James wrote:
    > I'm trying to encrypt a part of a url as follows:
    >
    > test.aspx?id=123&check=abc
    >
    > Basically, I'm using TripleDes encryption to encrypt the id, then include
    > this as check in the url to prevent tampering. I'm working from some code
    > from http://www.15seconds.com/Issue/021210.htm
    >
    > It seems to work fine except a few seem to through up problems as follows:
    >
    > Invalid character in a Base-64 string
    >
    > Line 83:
    > Line 84: 'convert from string to byte array
    > Line 85: Dim buffer As Byte() = Convert.FromBase64String(value)
    > Line 86: Dim ms As MemoryStream = New MemoryStream(buffer)
    > Line 87: Dim cs As CryptoStream = New CryptoStream(ms,
    > cryptoProvider.CreateDecryptor(KEY_192, IV_192), CryptoStreamMode.Read)
    >
    >
    > An example ID that throws up a problem is 1026 which gives the check
    > eIn9iD3i+JE=
    >
    > I'm guessing it is to do with the + sign, but even when urlencoded it gives
    > the same error.
    >
    > I can post more code if needed... but any advice would be great. Is there a
    > better / more reliable way to encrypt?
    >
    > Cheers
     
    bruce barker, Apr 24, 2007
    #2
    1. Advertising

  3. bruce barker wrote:
    > the + decodes to a space (as spaces are not allowed in a url).
    > urlencoding leaves it alone. you will need manually convert it to "%2b"
    > after performing a urlencode.
    >
    > -- bruce (sqlwork.com)
    >


    I tested this to be really sure, and it works exactly as I though it
    would. Using UrlEncode on a string containing a + does encode it into
    %2b. There is no need to do it manually.

    --
    Göran Andersson
    _____
    http://www.guffa.com
     
    =?UTF-8?B?R8O2cmFuIEFuZGVyc3Nvbg==?=, Apr 24, 2007
    #3
    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. =?Utf-8?B?UmFlZCBTYXdhbGhh?=

    Invalid character in a Base-64 string.

    =?Utf-8?B?UmFlZCBTYXdhbGhh?=, Aug 23, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    873
    =?Utf-8?B?UmFlZCBTYXdhbGhh?=
    Aug 23, 2005
  2. =?Utf-8?B?S29rZXRzbyBNYXNoYW8=?=

    Invalid character in a Base-64 string

    =?Utf-8?B?S29rZXRzbyBNYXNoYW8=?=, Sep 30, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    562
    =?Utf-8?B?S29rZXRzbyBNYXNoYW8=?=
    Sep 30, 2005
  3. Jon   Paal
    Replies:
    2
    Views:
    6,331
    Bruce Barker
    Mar 21, 2006
  4. Replies:
    1
    Views:
    19,778
    Alvin Bruney
    May 25, 2006
  5. kevin
    Replies:
    0
    Views:
    1,011
    kevin
    Jan 16, 2008
Loading...

Share This Page