0

I have a field in an SQL Server table that holds the string value of a checksum. The checksum is of a file and was calculated using the SHA1Cryptographic Service of vb.net. I used a Convert.TobBase64String after I computed the hash. Much later, after doing this on >300,000 files, I decided that I want my hash to be a string of the hex value of the hash (the reason for this is because I am now hashing files on a Unix machine and the program I use outputs it in hex). So I'd like to convert all of those digests to hex. Is there any way to convert the string directly to the hex representation within SQL server without having to go through and re-hash all of the files? Thanks in advance!

user1422348
  • 345
  • 1
  • 7
  • 23

1 Answers1

0

You should use a CLR to run those hashes through a VB.NEt program, and return the base HEX value: How to: Create and Run a CLR SQL Server User-Defined Function

Jason Carter
  • 915
  • 6
  • 15
  • How to create a hex string with .net isn't the most straight forward but there are multiple solutions http://stackoverflow.com/questions/623104/byte-to-hex-string/623119 – jbtule Apr 09 '13 at 15:06
  • If he can use VB.NET to get it back to the state he wants it (since he got it there using VB.NET) he can then output the new format using the CLR and use that value to update the field, so rather than having to hit 300k files, just manipulate the date itself. – Jason Carter Apr 09 '13 at 15:09
  • I was commenting that it wasn't straight forward to create the new format with .net/clr and pointing to the common question/answers for creating that format. – jbtule Apr 09 '13 at 15:15
  • Perhaps I should have clarified. I have .net code that can convert a digest to base64string as well as to hex (not sure if the hex was created the most efficient way possible, but it works). For the string, I just use Convert.ToBase64String(digest); For the hex, I iterate through each byte and append to a stringbuilder: `sb.AppendFormat("{0:X2}", b)`. In both cases, however, I have the original digest. So can I somehow go from Base64String to hex, even if i have to iterate through each character of the base64string? Thanks. – user1422348 Apr 10 '13 at 06:16
  • Okay, I understand a little more about CLR (although still extremely new to the concept and haven't actually tried it yet). I was hoping that there was something I could do with T-SQL but it seems I cannot. Thanks for your help Jason. – user1422348 Apr 14 '13 at 02:26