public string GetHMACValue(string encData, string encKey) { UTF8Encoding encoding = new UTF8Encoding(); byte[] keyBuff = encoding.GetBytes(encKey); byte[] hashMessage = null; using (var hmacsha256 = new HMACSHA256(keyBuff)) { byte[] dataBytes = encoding.GetBytes(encData); hashMessage = hmacsha256.ComputeHash(dataBytes); } return(HMACCipherCommon.ByteToString(hashMessage)); }
public string EncodeAES256(string plainText, string cipherKey, string cipherIV, CipherMode cipherMode, PaddingMode paddingMode) { byte[] byteKey = Encoding.UTF8.GetBytes(cipherKey); byte[] byteIV = Encoding.UTF8.GetBytes(cipherIV); string strEncode = string.Empty; byte[] bytePlainText = Encoding.UTF8.GetBytes(plainText); using (AesCryptoServiceProvider aesCryptoProvider = new AesCryptoServiceProvider()) { try { aesCryptoProvider.Mode = cipherMode; aesCryptoProvider.Padding = paddingMode; return(HMACCipherCommon.ByteToString(aesCryptoProvider.CreateEncryptor(byteKey, byteIV).TransformFinalBlock(bytePlainText, 0, bytePlainText.Length))); } catch { return(string.Empty); } } }