October 27, 2010 at 9:31 pm
Hi everyone,
I'm using the fciv utility to obtain a MD5 hash checksum value for a datafile, and store the checksum in an XML database. I then need to insert the checksum from the XML into a SQL table. I can do the insert from the XML into the database, but the database requires the checksum in hexadecimal, and fciv writes the hash value to the XML database in Base64 encoding.
Does anyone know how I can translate the Base64 to hexadecimal?
October 27, 2010 at 11:05 pm
Hi,
I would try Base64 => Varbinary => Hex
I don't think there is a direct conversion but I may be wrong.
Good luck!
October 27, 2010 at 11:07 pm
I've got the Base64 -> varbinary sorted... you wouldn't know about the -> Hex conversion would you?
I've been butting my head against this for about a week now, there's a blood stain on the wall and everything.
October 27, 2010 at 11:13 pm
christine.lawrie (10/27/2010)
I've got the Base64 -> varbinary sorted... you wouldn't know about the -> Hex conversion would you?I've been butting my head against this for about a week now, there's a blood stain on the wall and everything.
Wayne
Microsoft Certified Master: SQL Server 2008
Author - SQL Server T-SQL Recipes
October 27, 2010 at 11:17 pm
Indeed...
October 27, 2010 at 11:53 pm
Try:
-- Convert binary value in a variable to hexstring:
declare @hexbin varbinary(max);
set @hexbin = 0xabcedf012439;
select '0x' + cast('' as xml).value('xs:hexBinary(sql:variable("@hexbin") )', 'varchar(max)');
go
PS.
Have not tested this code
October 27, 2010 at 11:58 pm
Ah... Found this one in some old code of mine too...
master.dbo.fn_varbintohexstr()
October 28, 2010 at 12:01 am
You beat me to it... I had just found the lovely fn_varbintohexstr().
So, if I read the XML node into a varbinary, I can then run the function over the varbinary, and pass on the hexadecimal formatted MD5 checksum.
The people that want the #$!!!!!!! checksum will be very happy.
October 28, 2010 at 12:15 am
Now all that's left for you is to clean up the blood 😀
October 28, 2010 at 12:30 am
diamondgm (10/28/2010)
Now all that's left for you is to clean up the blood 😀
Agreed... I left a mess behind! :w00t:
Wayne
Microsoft Certified Master: SQL Server 2008
Author - SQL Server T-SQL Recipes
Viewing 10 posts - 1 through 9 (of 9 total)
You must be logged in to reply to this topic. Login to reply