0

I Have basically calculated SHA512 hash and I get it in byte[], all I want to do is to store it in my DB, the current infrastructure is such that i need to create a XML of my data and this XML gets passed to a SP which inserts the data. So the flow becomes

byte[] -> string (using BitConverter) -> XML -> binary(64)(using OPENXML)

I think this can be improved, but unfortunately I cannot change the infrastructure, so the XML has to be in between, also what happens is that the XML data I had -

1031B4BFC79B4E6357FE271FF2313D37A90E29FCAAEC850E5C4044547C1184AE

becomes

0x31003000330031004200340042004600430037003900420034004500360033003500370046004500320037003100460046003200330031003300440033003700

in the db

This does not look like the binary form of original data. Any explanation on whats happening?

0

3 Answers 3

2

The string that comes out looks like little-Endian Unicode of the original hex string.

I.e., 0x3100 for '1', 0x3000 for '0', 0x3300 for '3', 0x3100 for '1', 0x4200 for 'B', etc.

Sign up to request clarification or add additional context in comments.

Comments

2

If I were you, I wouldn't use BitConverter for such a purpose.

use

Convert.FromBase64String(string s);

and

Convert.ToBase64String(byte[] inArray);

instead.

if you want to know further information on Base64 and its structure, take a look to Base64 On Wikipedia

and if this does not help, please provide some more information and code about your problem

2 Comments

Thanks, I will remember that, but why dont we have Convert.ToBase128String, it should be just about using twice as many symbols and we have lots. I wonder what would be the most compact form
base 64 is useful when you want to transmit byte arrays using a text-based system such as http protocol, or just an xml. base 64 maps every 6 bit to a 8 bit representation. as you can see in the referenced link, there are 64 characters which are safe to transmit in a text-based media, but I don't believe that there are 128 ones of them. maybe that is why we don't have base 128. and about the compression, your size will grow with a ratio of 8/6 (or 4/3) when you convert it to base 64. I hope I helped
1

when you encode array of bytes to base 64 its string representation of orginal data so you can use Convert.FromBase64String(fieldvalue) to getting orginal byte data

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.