用c#做aes加密 为什么在线解密解不了
展开全部
/// <summary>
/// Aes解密
/// </summary>
/// <param name="source">源字符串</param>
/// <param name="key">aes密钥,长度必须32位</param>
/// <returns>解密后的字符串</returns>
public static string DecryptAes(string source, string key)
{
using (AesCryptoServiceProvider aesProvider = new AesCryptoServiceProvider())
{
aesProvider.Key = GetAesKey(key);
aesProvider.Mode = CipherMode.ECB;
aesProvider.Padding = PaddingMode.PKCS7;
using (ICryptoTransform cryptoTransform = aesProvider.CreateDecryptor())
{
byte[] inputBuffers = Convert.FromBase64String(source);
byte[] results = cryptoTransform.TransformFinalBlock(inputBuffers, 0, inputBuffers.Length);
aesProvider.Clear();
return Encoding.UTF8.GetString(results);
}
}
}
/// Aes解密
/// </summary>
/// <param name="source">源字符串</param>
/// <param name="key">aes密钥,长度必须32位</param>
/// <returns>解密后的字符串</returns>
public static string DecryptAes(string source, string key)
{
using (AesCryptoServiceProvider aesProvider = new AesCryptoServiceProvider())
{
aesProvider.Key = GetAesKey(key);
aesProvider.Mode = CipherMode.ECB;
aesProvider.Padding = PaddingMode.PKCS7;
using (ICryptoTransform cryptoTransform = aesProvider.CreateDecryptor())
{
byte[] inputBuffers = Convert.FromBase64String(source);
byte[] results = cryptoTransform.TransformFinalBlock(inputBuffers, 0, inputBuffers.Length);
aesProvider.Clear();
return Encoding.UTF8.GetString(results);
}
}
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询