我正在爲下面的代碼製作等效的java代碼。但我可以做一些返回相同結果的東西encodedString。我可以使用什麼Java類來實現相同的結果?C#HMAC到Java
//Set the Hash method to SHA1
HMAC hash;
switch (validation)
{
case MachineKeyValidation.MD5:
hash = new HMACMD5();
break;
case MachineKeyValidation.SHA1:
default:
hash = new HMACSHA1();
break;
}
//Get the hash validation key as an array of bytes
hash.Key = HexToByte(validationKey);
//Encode the password based on the hash key and
//converts the encrypted value into a string
encodedString = Convert.ToBase64String(hash.ComputeHash(Encoding.Unicode.GetBytes(password)));
在此先感謝! :)
它不工作:「java.security.NoSuchAlgorithmException:找不到任何配套商SHA1」 – Victor 2011-02-15 19:58:52
編輯,以添加一些代碼來幫助你縮小問題。 – 2011-02-15 20:52:15