Home > Net > Look at elder advice StringToHexByte transformation, the second day
Look at elder advice StringToHexByte transformation, the second day
Time:09-30
Docking with a company's ability to each other as Java USES bcprov - jdk16-143. The jar package methods in the Hex, decode () to decrypt a hexadecimal string, I now want to use. Net implement this method, failure, unable to follow-up work, hope the great god directions, Debugging results are as follows:
Var hexString="6 ff5cb38ddef84d5b7fdaadcbe249061"; //CSDN great god code, the output is: 111-245-203-56-221-239-132-213-183-253-170-220-190-36-144-97 (ToString (), digital byte value) //and Hex. Decode (), output is not consistent: the 111-11-5 356-35-17-124-43-73-3-8 6-36-6636-11297 Public static byte [] ToHex (this string hexString) { Var datas=new byte [hexString. Length/2]; Var j=0; For (var I=0; i Datas [j++]=the Convert. ToByte (hexString. Substring (I, 2), 16); Return datas; }
Public int decode (final String s, final OutputStream OutputStream) throws IOException { int n=0; Int length; For (length=s.l ength (); Length & gt; 0 & amp; & Ignore (s.c harAt (length - 1)); - length) {} int i=0; While (I & lt; Length) { While (I & lt; Length & amp; & Ignore (s.c harAt (I))) { + + I; } Byte b; For (b=this. DecodingTable [s.c harAt (i++)]; i Final byte b2=this. DecodingTable [s.c harAt (i++)]; If ((b | b2) & lt; 0 { Throw new IOException (" invalid characters encountered in Hex string "); } OutputStream. Write (b & lt; <4 | b2); + + n. } Return n. }
CodePudding user response:
Java code public static byte [] decodeHexUpper (String STR) throws UnsupportedEncodingException Can't be output 111-11 - 5356-35... Because byte maximum value is 255, obviously can't be a 5356 byte output, You may want to check whether the output of the Java example,
Java Hex. Decode () source have to skip the Hex character processing, is this your c # realize no, Hex. For example, decode () can decode "f5 cb 6 f," you can't, c # now see only the little difference,