Ouputing varbinary data

Ask a Question related to Coldfusion Database Access, Design and Development.

  1. #1

    Default Ouputing varbinary data

    Hello CF fellows,

    When outputing varbinary data directly from a column of datatype "varbinary"
    in MS SQL Server, I get the error "ByteArray objects cannot be converted to
    strings" in ColdFusion MX. I don't get this error in earlier version of CF,
    e.g. CF 4.0...

    Does anybody know how I can fix this?



    For example, if I have a column called "User_ID" (datatype=varbinary), when I
    output it as follows, I get the error.

    <cfoutput>
    GetVarbinary.User_ID
    </cfoutput>

    AZDeveloper Guest

  2. Similar Questions and Discussions

    1. Linking data, searching data, and format the data file
      I'm sorta new to flash and integrating data and components...I'm usu. an interface designer. I'm trying to link a combo box to a file doesn't...
    2. How Many VarBinary for each Ascii Char Aes Encrypted KeySize=256,BlockSize=256
      Hi. I'm wanting to encrypt customer name, address, etc. information using Aes with a KeySize of 256 and a BlockSize of 256. Either for each ascii...
    3. abnormal program termination with dynamic data, but not with fixed data
      hi everyone. I am stumped! I have code that is part of a simple persistent object manager. The system takes an object, builds an update...
    4. How to get hexadecimal values into varbinary columns?
      use numeric literals not string. INSERT INTO table1 VALUES (0xA6D4632C1) note: if you cast a string, the actual ascii codes are used. INSERT...
    5. Conversion of Varbinary into varchar
      Dear All, I have written a stored procedure which returns a Varbinary column from MS SQl Server 7 database. I tried converting the same into...
  3. #2

    Default Re: Ouputing varbinary data

    You might want to try the suggestions in [url]http://www.macromedia.com/cfusion/webforums/forum/messageview.cfm?catid=6&threadid=976780[/url]. A) cast as varchar in query or B) use java.lang.String
    mxstu Guest

  4. #3

    Default Re: Ouputing varbinary data

    Hi mxstu,

    First of all, I'd like to thank you very much in advance!

    Here's the SQL code that I use to encrypt some username and store it in a
    column of datatype "varbinary" in MS SQL Server.

    What I need help on is: I'd like to decrypt this varbinary Username_Encrypted
    = ''0xAAC1D3CFCEA8' back to "JasonH".

    I've tried using your CAST AS VARCHAR approach but I don't really know how to
    do it. Please help!

    Thank you!




    DECLARE @position int, @string varchar(16), @binary binary(1), @varbinary
    varbinary(32)

    SET @position = 1

    SET @string = 'JasonH'

    SET @varbinary = 0x


    WHILE @position <= DATALENGTH(@string)

    BEGIN

    SET @binary = CAST(ASCII(SUBSTRING(@string, @position, 1)) + 96 AS
    binary(1))

    SET @varbinary = @varbinary + @binary

    SET @position = @position + 1

    END

    SELECT Username = @string, Username_Encrypted = @varbinary

    AZDeveloper Guest

  5. #4

    Default Re: Ouputing varbinary data

    If it wasn't encrypted, I would just suggest using a simple

    SELECT cast(yourVarbinaryColumn AS varchar(16)) FROM yourTable

    There might be a better way, but I would probably just reverse the encryption
    logic. Maybe put it in a UDF depending on your security concerns.






    CREATE FUNCTION dbo.decryptString (@binString varbinary(32))
    RETURNS varchar(16)
    AS
    BEGIN
    DECLARE @revertString varchar(16)
    DECLARE @finalString varchar(16)
    DECLARE @varbinary varbinary(32)
    DECLARE @string varchar(1)
    DECLARE @position int

    SET @finalString = ''
    SET @position = 1
    SET @revertString = (SELECT CAST(@binString AS varchar(16)))

    WHILE @position <= DATALENGTH(@revertString)
    BEGIN
    SET @string = CAST(CHAR(ASCII(SUBSTRING(@revertString, @position, 1))-96)
    AS varchar(1))
    SET @finalString = @finalString + @string
    SET @position = @position + 1
    END


    RETURN @finalString

    END
    GO

    SELECT dbo.decryptString(0xAAC1D3CFCEA8)

    mxstu Guest

  6. #5

    Default Re: Ouputing varbinary data

    :)

    Thank you very much, mxstu. Your code is extremely helpful and is greatly apprecitated!
    AZDeveloper 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