-1

I have a column in an SQL-Server table, containing information like the following:

Data
0x0056794433020000632700C90079058303F2000102EA40C0000000150001000100020001001500010001000136BB00000000000001F50000000100010001000100003135343131313838323230393239393638340000
0x0056C944370200007827007200C9058303F2000102EA40BD0000000E003E000200020001000E00010001000136C5020036B1000001F50000000100010001000100003339303038373030333533323331343536310000
0x0056C9443102000078AF007100C9058303F2000102EA40BB0000000D0033000500020002000D00010001000136C5020036B1000001F50000000100010001000100003339303038373030333533323338323937330000

This information is written as follows (VB.Net code):

Dim oPar5 As New SqlParameter("@Data", Convert.ToBase64String(data)) 

I'm trying to decode this, but I feel I'm being thrown around because of my lack of knowledge on the subject (ChatGpt, e.g., is constantly dragging XML into this, while this has nothing to do with it).

So I decided to start with the basics: what are Base64 strings? Only when this is clear, I might start trying to convert this into Byte arrays (as a test, the fourth byte should always be "D", "K" or "Q", other values are not possible).

Can anybody give me a start?

2
  • The 3 data rows are displayed in hexadecimal notation. So, I am not sure what this has to do with Base64, which is a way to encode binary data as string typically looking like this bGlnaHQgd29yay4= Commented Jan 27 at 11:05
  • You would add a parameter like this command.Parameters.Add("@Data", SqlDbType.Binary, b.Length).Value = b where b is a byte array. Commented Jan 27 at 11:11

1 Answer 1

3

Base64 is a 6-bit encoding of 8-bit binary data, typically using characters a-z A-Z 0-9 / + (and usually = as final padding). "Base64 strings" would therefore be plain ASCII strings that contain such encoded data.

Dim data() as byte = { &H01, &H23, &H45, &H67, &H89 } Console.WriteLine(Convert.ToBase64String(data)) # output: ASNFZ4k= 

The strings in your table are not Base64; they have the data encoded in hexadecimal (which I assume is only what the SQL client shows while the actual column stores non-encoded binary data). So my guess is that either the VB.Net code doesn't match the database, or there is some additional code on the SQL query side of the operation which undoes the Base64 encoding before storing into the database (e.g. BASE64_DECODE(@Data) or something along those lines).

$ cat example1.txt | sed s/^0x// | unhex | hd 00000000 00 56 79 44 33 02 00 00 63 27 00 c9 00 79 05 83 |.VyD3...c'...y..| ^-- has a 'D' 00000010 03 f2 00 01 02 ea 40 c0 00 00 00 15 00 01 00 01 |......@.........| 00000020 00 02 00 01 00 15 00 01 00 01 00 01 36 bb 00 00 |............6...| 00000030 00 00 00 00 01 f5 00 00 00 01 00 01 00 01 00 01 |................| 00000040 00 00 31 35 34 31 31 31 38 38 32 32 30 39 32 39 |..15411188220929| 00000050 39 36 38 34 00 00 |9684..| 

The Base64-encoded version of the same value would be:

AFZ5RDMCAABjJwDJAHkFgwPyAAEC6kDAAAAAFQABAAEAAgABABUAAQABAAE2uwAAAAAAAAH1AAAA AQABAAEAAQAAMTU0MTExODgyMjA5Mjk5Njg0AAA= 

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.