Get the same hash string on .NET and Java using the same hashing algorithm?
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   G_Tsang
Posted On:   Friday, July 9, 2004 04:27 PM

Hello All, Is it possible to get the same hashed string on .NET and Java using the same hashing algorithm (e.g. MD5, SHA)?? On .NET side, the token is generated using the following code: Private Function HashEncrypt(ByVal strInput as String) As String Dim bytHash as Byte() Dim uEncode As New System.Text.UnicodeEncoding ' - - - STORE THE SOURCE STRING INTO A BYTE ARRAY - - - Dim bytSource() As Byte = uEncode.GetBytes(strInput) Dim SHA1 As New System.Security.Cryptography.SHA1CryptoServiceProvider ' - - - CREATE THE HASH - - - bytHash = SHA1.ComputeHash(bytSource) ' - - - RETURN AS A BASE64 ENCODED STRING - - - Return Convert.ToB   More>>

Hello All,


Is it possible to get the same hashed string on .NET and Java using the same hashing algorithm (e.g. MD5, SHA)??


On .NET side, the token is generated using the following code:

			

Private Function HashEncrypt(ByVal strInput as String) As String
Dim bytHash as Byte()
Dim uEncode As New System.Text.UnicodeEncoding
' - - - STORE THE SOURCE STRING INTO A BYTE ARRAY - - -
Dim bytSource() As Byte = uEncode.GetBytes(strInput)
Dim SHA1 As New System.Security.Cryptography.SHA1CryptoServiceProvider
' - - - CREATE THE HASH - - -
bytHash = SHA1.ComputeHash(bytSource)
' - - - RETURN AS A BASE64 ENCODED STRING - - -
Return Convert.ToBase64String(bytHash)
End Function




On the java side, the token is generated as follow:
			

MessageDigest _digester = null;
_digester = MessageDigest.getInstance("SHA1");
_digester.reset();
byte[] utf8 = _msg.getBytes("UTF-8");
_digester.update(utf8);
byte[] _tokenBytes = _digester.digest();
String s = new sun.misc.BASE64Encoder().encode(_tokenBytes);

Thanks for your help!

Grace    <<Less

Re: Get the same hash string on .NET and Java using the same hashing algorithm?

Posted By:   Sean_Owen  
Posted On:   Friday, July 9, 2004 04:31 PM

Does this code give the same hash value or not? That seems like the first thing to test!
About | Sitemap | Contact