So a byte is a byte is a byte unless it is not! That in one sentence sums up my findings from yesterday. A byte in .NET represents a unsigned byte (0 - 255) automatically but a byte in Java is a signed byte(-128 - 127) and no there is no way to get an unsigned byte. I never really came across this problem till I was running some encryption algorithms on both. I need to encrypt a string in .NET and decrypt it on Java. For this I was converting the byte array into a hex string and asking users to enter it. However, because of the difference in interpretation of bytes I am running into problems.
NOTE: There is a signed byte in .NET available called ssbyte. I am not sure how an encryption algorithm can stuff it's data into it thgh. Sad! Sad! Sad!
CORRECTION: Okay so I had a brain-dead day and worte this out. It does not really matter how the two languages interpret the bits as long as the bits are the same going in to the encryption/decryption libraries.I am keeping this here to remind myself how stupid I can be.
.net byte => 0 ~ 255
java byte => -128 ~ 127
.net byte - 128 = java byte
출처 : http://geekswithblogs.net/rishi/archive/2006/01/27/67310.aspx
NOTE: There is a signed byte in .NET available called ssbyte. I am not sure how an encryption algorithm can stuff it's data into it thgh. Sad! Sad! Sad!
CORRECTION: Okay so I had a brain-dead day and worte this out. It does not really matter how the two languages interpret the bits as long as the bits are the same going in to the encryption/decryption libraries.I am keeping this here to remind myself how stupid I can be.
.net byte => 0 ~ 255
java byte => -128 ~ 127
.net byte - 128 = java byte
출처 : http://geekswithblogs.net/rishi/archive/2006/01/27/67310.aspx