private static uint[] Decrypt(uint[] v, uint[] k) { int num = v.Length - 1; if (num < 1) { return(v); } uint y = v[0]; int num2 = 6 + 52 / (num + 1); for (uint num3 = (uint)((long)num2 * (long)(-1640531527)); num3 != 0u; num3 -= 2654435769u) { uint e = num3 >> 2 & 3u; int i; uint z; for (i = num; i > 0; i--) { z = v[i - 1]; y = (v[i] -= XXTEA.MX(num3, y, z, i, e, k)); } z = v[num]; y = (v[0] -= XXTEA.MX(num3, y, z, i, e, k)); } return(v); }
private static uint[] Encrypt(uint[] v, uint[] k) { int num = v.Length - 1; if (num < 1) { return(v); } uint z = v[num]; uint num2 = 0u; int num3 = 6 + 52 / (num + 1); while (0 < num3--) { num2 += 2654435769u; uint e = num2 >> 2 & 3u; int i; uint y; for (i = 0; i < num; i++) { y = v[i + 1]; z = (v[i] += XXTEA.MX(num2, y, z, i, e, k)); } y = v[0]; z = (v[num] += XXTEA.MX(num2, y, z, i, e, k)); } return(v); }
/// <summary> /// 数据解密 /// </summary> /// <param name="data"></param> /// <param name="key"></param> /// <returns></returns> public static byte[] Decrypt(byte[] data, byte[] key) { if (data.Length == 0) { return(data); } return(XXTEA.ToByteArray(XXTEA.Decrypt(XXTEA.ToUInt32Array(data, false), XXTEA.ToUInt32Array(XXTEA.FixKey(key), false)), true)); }
public static byte[] Decrypt(byte[] data, string key) { return(XXTEA.Decrypt(data, XXTEA.utf8.GetBytes(key))); }
public static byte[] Encrypt(string data, string key) { return(XXTEA.Encrypt(XXTEA.utf8.GetBytes(data), XXTEA.utf8.GetBytes(key))); }