开发者

passing byte[] from C# to sql table via XML

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 infrast开发者_StackOverflowructure, 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?


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.


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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜