NetSkycn.Security/RC2Provider.cs
(完整代码) 2KBusing System;
using System.Collections.Generic;
using System.Text;
using System.Security.Cryptography;
using System.IO;
namespace NetSkycn.Security
{
/// <summary>
/// RC2加密解密
/// </summary>
public sealed class RC2Provider
{
private RC2Provider()
{
}
public static string Encrypt(string sourceString,string key)
{
if (string.IsNullOrEmpty(sourceString))
{
throw new ArgumentNullException("encryptString", "不能为空");
}
byte[] keyBytes = Encoding.UTF8.GetBytes(key.Substring(0, 8));
byte[] keyIV = keyBytes;
byte[] inputByteArray = Encoding.UTF8.GetBytes(sourceString);
RC2CryptoServiceProvider provider = new RC2CryptoServiceProvider();
MemoryStream mStream = new MemoryStream();
CryptoStream cStream = new CryptoStream(mStream, provider.CreateEncryptor(keyBytes, keyIV), CryptoStreamMode.Write);
cStream.Write(inputByteArray, 0, inputByteArray.Length);
cStream.FlushFinalBlock();
return Convert.ToBase64String(mStream.ToArray());
}
/// <summary>
/// RC2解密
/// </summary>
/// <param name="decryptString">要解密的字符串</param>
/// <returns></returns>
public static string Decrypt(string decryptString,string key)
{
if (string.IsNullOrEmpty(decryptString))
{
throw new ArgumentNullException("decryptString", "不能为空");
}
byte[] keyBytes = Encoding.UTF8.GetBytes(key.Substring(0, 8));
byte[] keyIV = keyBytes;
byte[] inputByteArray = Convert.FromBase64String(decryptString);
RC2CryptoServiceProvider provider = new RC2CryptoServiceProvider();
MemoryStream mStream = new MemoryStream();
CryptoStream cStream = new CryptoStream(mStream, provider.CreateDecryptor(keyBytes, keyIV), CryptoStreamMode.Write);
cStream.Write(inputByteArray, 0, inputByteArray.Length);
cStream.FlushFinalBlock();
return Encoding.UTF8.GetString(mStream.ToArray());
}
}
}
24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明
AI 解读 AI
登录后可用,每次 10 算力,解读结果公开显示在下面。
还没有人解读过这个文件。