0

This is my java code.

byte[] bytes = { 0x35, 0x24, 0x76, 0x12 };
  MessageDigest m = MessageDigest.getInstance("MD5");
  byte[] digest = m.digest(bytes);

C#

 byte[] bytes = { 0x35, 0x24, 0x76, 0x12 };
 MD5 md5 = new MD5CryptoServiceProvider();
 byte[] result = md5.ComputeHash(bytes);

I have noticed that the resulting bytes are different, I am new in java, can someone explain.. thanks..

the result are

c#

[  58,  74, 139,   3, 244, 223, 176, 230, 227, 252, 130, 221,  54, 159, 112, 239]

java

[  58,  74,-117,   3, -12, -33, -80, -26, -29,  -4,-126, -35,  54, -97, 112, -17]
Sir Rufo
  • 18,395
  • 2
  • 39
  • 73

1 Answers1

1

You can see on the different results that all positive values are the same. Only the negative ones are different. In .net byte type is unsigned so its range is from 0 to 255. In Java the byte type has a range from -128 to 127. You can read it here.

Stivi C.
  • 284
  • 2
  • 4
  • do this mean that if i use the byte in c# as a key the java wont be able to decrypt it ? bec the produce different . did i hit a limitation of this system? – Cris Jun Virtudazo Dec 04 '17 at 01:40
  • Take a look on this question: [https://stackoverflow.com/questions/17754262/c-sharp-unsigned-bytes-encryption-to-java-signed-bytes-decryption]. Maybe it depens on the used encryption algorithm but i think it will be possible to decrypt something in c# what is encrypted by java application. – Stivi C. Dec 04 '17 at 07:38