110,567
社区成员
发帖
与我相关
我的任务
分享
public class AEncryption
{
/// <summary>
/// 加密串
/// </summary>
/// <param name="buffer">密钥</param>
/// <param name="len">长度=8</param>
/// <param name="key">传入的明码密码</param>
/// <returns></returns>
public static string DecodeString(string buffer, int len, string key)
{
try
{
if (buffer == null) throw new ArgumentNullException("buffer", "传入密钥为空");
if (string.IsNullOrEmpty(key)) key = string.Empty;
char[] pbuffer = new char[1024];
char[] pkey = new char[80];
AEncryption encryption = new AEncryption();
buffer.ToCharArray().CopyTo(pbuffer, 0);
key.ToCharArray().CopyTo(pkey, 0);
encryption.Secret(pbuffer, len, pkey);
byte[] encryptBytes = CharArray2ByteArray(len, encryption);
return Convert.ToBase64String(encryptBytes);
}
catch (Exception ex)
{
throw ex;
}
}
private static byte[] CharArray2ByteArray(int len, HisEncryption encryption)
{
byte[] ret = new byte[len];
for (int i = 0; i < len; i++)
{
ret[i] = Convert.ToByte(encryption.pass[i]);
}
return ret;
}
}
private void Secret(char[] buffer, int len, char[] passkey)
{
int zs;
FirstKey(passkey);
zs = Association(len);
LoadKey();
pass = new char[buffer.Length];
buffer.CopyTo(pass,0);
Exchange(pass, len, zs);
}