這個代碼會報異常,出現PNSE 經查找各種文檔發現一下使用辦法是Ok的,有沒有其它的辦法呢? ...
KeyedHashAlgorithm algorithm = KeyedHashAlgorithm.Create(algorithmName.ToString().ToUpper(CultureInfo.InvariantCulture)); if (null == algorithm) throw new InvalidOperationException("Please specify a KeyedHashAlgorithm to use."); try { algorithm.Key = key; byte[] bytes = algorithm.ComputeHash(data); return bytes; } finally { algorithm.Clear(); }
這個代碼會報異常,出現PNSE
經查找各種文檔發現一下使用辦法是Ok的,有沒有其它的辦法呢?
try { var keyBytes = Encoding.UTF8.GetBytes(key); var hmac = new HMACSHA1(keyBytes); byte[] bytes = hmac.ComputeHash(data); return Convert.ToBase64String(bytes); } catch (Exception e) { throw e; } finally { }
HMACSHA256 hashAlgorithm = new HMACSHA256(key);
return hashAlgorithm.ComputeHash(Encoding.UTF8.GetBytes(data));