Quantcast
Channel: Security
Viewing all articles
Browse latest Browse all 4737

Converting Java code to VB.Net Problems with ComputeHash

$
0
0

Hi,

Converting Java code to VB.Net and all works fine bar one call to System.Security.Cryptography.SHA1Managed.ComputeHash

The code below is the Java that I am having trouble with and is fixed because it is out of our control.

MessageDigest md = MessageDigest.getInstance("SHA-1");
md.reset();
md.update(phrase);
byte[] digest = md.digest();

Now, I have replicated this code in VB.Net, but the fundamental issue is the fact that a Byte in Java is a signed value ranging between -127 and 127, whereas a byte in VB.Net is an unsigned value ranging between 0 and 256.

Now I have so far got around this by simply creating an SByte array and checking to see if the value held is greater then 127, if it is, then subtract 256. Sorted.

The problem I am having is based around the ComputeHash. It only takes a Byte array as its parameter. Trouble is if I convert an SByte array that hold a negative value, then the negative values are replaced by the original value (-30 becomes 226) hence any returned values from the ComputeHash call are not the same as if I called the md.digest call in Java.

Can this be fixed?


Viewing all articles
Browse latest Browse all 4737

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>