1 Star 0 Fork 0

卦者灵風/onmyojiPoXiao

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
TextEncryptUtils.cs 1.94 KB
一键复制 编辑 原始数据 按行查看 历史
yinpeng zhou 提交于 2022-09-13 00:13 . add new
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
namespace PoXiao
{
internal class TextEncryptUtils
{
public static string AesEncrypt(string str, string key)//aes加密
{
if (string.IsNullOrEmpty(str)) return null;
Byte[] toEncryptArray = Encoding.UTF8.GetBytes(str);
RijndaelManaged rm = new RijndaelManaged
{
Key = Encoding.UTF8.GetBytes(key),
Mode = CipherMode.ECB,
Padding = PaddingMode.PKCS7
};
ICryptoTransform cTransform = rm.CreateEncryptor();
Byte[] resultArray = cTransform.TransformFinalBlock(toEncryptArray, 0, toEncryptArray.Length);
return Convert.ToBase64String(resultArray);
}
public static string AesDecrypt(string str, string key)//aes解密
{
if (string.IsNullOrEmpty(str)) return null;
Byte[] toEncryptArray = Convert.FromBase64String(str);
RijndaelManaged rm = new RijndaelManaged
{
Key = Encoding.UTF8.GetBytes(key),
Mode = CipherMode.ECB,
Padding = PaddingMode.PKCS7
};
ICryptoTransform cTransform = rm.CreateDecryptor();
Byte[] resultArray = cTransform.TransformFinalBlock(toEncryptArray, 0, toEncryptArray.Length);
return Encoding.UTF8.GetString(resultArray);
}
public static string Md532(string str)
{
var md5Csp = new MD5CryptoServiceProvider();
byte[] md5Source = Encoding.UTF8.GetBytes(str);
byte[] md5Out = md5Csp.ComputeHash(md5Source);
string result = "";
for (int i = 0; i < md5Out.Length; i++)
{
result += md5Out[i].ToString("x2");
}
return result;
}
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/galileo2/onmyoji-poxiao.git
[email protected]:galileo2/onmyoji-poxiao.git
galileo2
onmyoji-poxiao
onmyojiPoXiao
master

搜索帮助