String Gets Truncated: VBScript End of String Character?

Discussion in 'ASP General' started by Mike, Aug 24, 2005.

  1. Mike

    Mike Guest

    Help, I am using an encryption routine that occasionally will encrypt a
    string using some extended ASCII characters (ASCII code > 128)

    I am wondering if there is a reserved character in VB that signifies
    the end of a string of characters.

    Here is what happens: I am encrypting certain fields before adding
    them to a SQL string. On occassion, the SQL string will simply end in
    the middle of the encrypted value.

    Example code

    sSQL = "EXEC SaveDetails " & _
    " @iDetailID = " & iDetailID & ", " & _
    " @sEncryptedText = '" & _
    replace(EncryptText(sText),"'","''") & "', " & _
    " @iOtherValue = 6"

    Normally Response.Write would print something like this:

    using Response.Write(Server.HTMLEncode(sSQL)):

    EXEC SaveDetails @iDetailID = 3, @sEncryptedText = 'aw@##@QASV@#AV (!',
    @iOtherValue = 6

    Occasionally on certain inputs for sEncryptedText it will print:

    EXEC SaveDetails @iDetailID = 3, @sEncryptedText = '@#DFVIDXZI

    Is my encryption algorithm possible generating a reserved character
    that signifies the end of a string? Does such a character exist in
    VBscript? Any help would be appreciated.

    FYI, I'd rather not post my encryption routine. Please let me know if
    you feel it would be necessary.
    Mike, Aug 24, 2005
    #1
    1. Advertising

  2. Mike wrote:
    > Help, I am using an encryption routine that occasionally will encrypt
    > a string using some extended ASCII characters (ASCII code > 128)
    >
    > I am wondering if there is a reserved character in VB that signifies
    > the end of a string of characters.
    >
    > Here is what happens: I am encrypting certain fields before adding
    > them to a SQL string. On occassion, the SQL string will simply end in
    > the middle of the encrypted value.
    >
    > Example code
    >
    > sSQL = "EXEC SaveDetails " & _
    > " @iDetailID = " & iDetailID & ", " & _
    > " @sEncryptedText = '" & _
    > replace(EncryptText(sText),"'","''") & "', " & _
    > " @iOtherValue = 6"
    >
    > Normally Response.Write would print something like this:
    >
    > using Response.Write(Server.HTMLEncode(sSQL)):
    >
    > EXEC SaveDetails @iDetailID = 3, @sEncryptedText = 'aw@##@QASV@#AV
    > (!', @iOtherValue = 6
    >
    > Occasionally on certain inputs for sEncryptedText it will print:
    >
    > EXEC SaveDetails @iDetailID = 3, @sEncryptedText = '@#DFVIDXZI
    >
    > Is my encryption algorithm possible generating a reserved character
    > that signifies the end of a string? Does such a character exist in
    > VBscript? Any help would be appreciated.
    >
    > FYI, I'd rather not post my encryption routine. Please let me know if
    > you feel it would be necessary.


    Try using parameters (in this example "conn" is a previously opened
    connection object):

    conn.SaveDetails iDetailID, EncryptText(sText), 6

    The bonus (if this solves your problem) is that using parameters saves you
    the extra step of escaping your embedded apostrophes - less processing
    needed.

    Bob Barrows
    --
    Microsoft MVP -- ASP/ASP.NET
    Please reply to the newsgroup. The email account listed in my From
    header is my spam trap, so I don't check it very often. You will get a
    quicker response by posting to the newsgroup.
    Bob Barrows [MVP], Aug 25, 2005
    #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. Bertus Dam
    Replies:
    5
    Views:
    850
    Bertus Dam
    Aug 29, 2003
  2. jza

    File name gets truncated

    jza, May 8, 2004, in forum: C Programming
    Replies:
    9
    Views:
    374
    Darrell Grainger
    May 10, 2004
  3. doltharz
    Replies:
    11
    Views:
    268
    doltharz
    Aug 3, 2003
  4. Jack
    Replies:
    4
    Views:
    142
    Paxton
    Jan 11, 2006
  5. Jack
    Replies:
    11
    Views:
    276
Loading...

Share This Page