javaのプログラムで入力されたパスワードをMessageDigestを使用してハッシュ値にしているプログラムがあります。
これをVB2005でも同じデータから同じハッシュ値に計算をしたいのですが値が合わない
状態です。
java側のソースは下記です。
try {
String password;
String salt;
byte objAByte[];
byte objBByte[];
password ="********";
salt ="63204";
MessageDigest md = MessageDigest.getInstance("SHA-256"); System.arraycopy(objAByte,0,objCByte,0,objAByte.length); System.arraycopy(objBByte,0,objCByte,objAByte.length, objBByte.length); //md.update(password.getBytes("UTF-8")); //md.update(salt.getBytes("UTF-8")); byte objByte[]; objByte = md.digest(); } catch (NoSuchAlgorithmException ea) { } catch (UnsupportedEncodingException ea) { } } private static String bin2hex(byte[] data) { StringBuffer sb = new StringBuffer(); for (byte b : data) { String s = Integer.toHexString(0xff & b); if (s.length() == 1) { sb.append("0"); } sb.append(s); } return sb.toString(); }
VB側のソースは下記です。
Dim objSecByte() As Byte
Dim strSignerutWork As String
Dim strSecret As String = ”****”
objSecByte = System.Text.Encoding.UTF8.GetBytes(strSecret) Dim objsha256 As New System.Security.Cryptography.HMACSHA256() Dim objSigByte() As Byte Dim objSigWorkByte() As Byte Dim result As New System.Text.StringBuilder() strSignerutWork = "63204" objSigByte = System.Text.Encoding.UTF8.GetBytes(strSignerutWork) Dim objTest(objSigByte.Length + objSecByte.Length - 1) As Byte objSecByte.CopyTo(objTest, 0) objSigByte.CopyTo(objTest, objSecByte.Length) objSigWorkByte = objsha256.ComputeHash(objTest) For inti As Integer = 0 To objSigWorkByte.Length - 1 result.AppendFormat("{0:X2}", objSigWorkByte(inti)) Next
ハッシュ値の計算後16進数に変換した値は
JAVA側は751b3516046fe1591601da0308ed4be4c649029f7b69550c6d2afd4c2f441508
VB側は207E27FCFBCE78212712DDB43F05D8A765391E8B4D22A2B04CCE6F9FB863C6FE
になっています。
そもそもMessageDigestとCryptographyでハッシュ計算自体が違うのでしょうか?
回答1件
あなたの回答
tips
プレビュー