直接贴出代码,如果有问题可以查看本类的示例项目本项目的git地址。
以下是静态密钥的类。
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
namespace AesEncrypt
{
/// <summary>
/// Aes加密算法适用于固定的加解密
/// </summary>
public static class AesEncrypt
{
/// <summary>
/// 对称算法的密钥
/// </summary>
private readonly static byte[] aesKey = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32 };
/// <summary>
/// 对称算法的初始化向量
/// </summary>
private readonly static byte[] aesIV = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 };
/// <summary>
/// 加密
/// </summary>
/// <param name="Text">被加密的字符串</param>
/// <returns>Base64</returns>
public