1 Star 0 Fork 663

CyrusZhou/OpenAuth.Core

forked from 李玉宝/OpenAuth.Core
暂停
 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
Encryption.cs 2.14 KB
一键复制 编辑 原始数据 按行查看 历史
李玉宝 提交于 2018-06-05 15:07 . Infrastructure commit
using System;
using System.Security.Cryptography;
using System.Text;
namespace Infrastructure
{
public class Encryption
{
private static string encryptKey = "4h!@w$rng,i#$@x1%)5^3(7*5P31/Ee0";
//默认密钥向量
private static byte[] Keys = { 0x41, 0x72, 0x65, 0x79, 0x6F, 0x75, 0x6D, 0x79, 0x53, 0x6E, 0x6F, 0x77, 0x6D, 0x61, 0x6E, 0x3F };
/// <summary>
/// 加密
/// </summary>
/// <param name="encryptString"></param>
/// <returns></returns>
public static string Encrypt(string encryptString)
{
if (string.IsNullOrEmpty(encryptString))
return string.Empty;
RijndaelManaged rijndaelProvider = new RijndaelManaged();
rijndaelProvider.Key = Encoding.UTF8.GetBytes(encryptKey.Substring(0, 32));
rijndaelProvider.IV = Keys;
ICryptoTransform rijndaelEncrypt = rijndaelProvider.CreateEncryptor();
byte[] inputData = Encoding.UTF8.GetBytes(encryptString);
byte[] encryptedData = rijndaelEncrypt.TransformFinalBlock(inputData, 0, inputData.Length);
return Convert.ToBase64String(encryptedData);
}
/// <summary>
/// 解密
/// </summary>
/// <param name="decryptString"></param>
/// <returns></returns>
public static string Decrypt(string decryptString)
{
if (string.IsNullOrEmpty(decryptString))
return string.Empty;
try
{
RijndaelManaged rijndaelProvider = new RijndaelManaged();
rijndaelProvider.Key = Encoding.UTF8.GetBytes(encryptKey.Substring(0, 32));
rijndaelProvider.IV = Keys;
ICryptoTransform rijndaelDecrypt = rijndaelProvider.CreateDecryptor();
byte[] inputData = Convert.FromBase64String(decryptString);
byte[] decryptedData = rijndaelDecrypt.TransformFinalBlock(inputData, 0, inputData.Length);
return Encoding.UTF8.GetString(decryptedData);
}
catch
{
return "";
}
}
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C#
1
https://gitee.com/CyrusZHou/OpenAuth.Core.git
[email protected]:CyrusZHou/OpenAuth.Core.git
CyrusZHou
OpenAuth.Core
OpenAuth.Core
master

搜索帮助