using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security.Cryptography;
using System.Runtime.InteropServices;
namespace JsonTextDemo
{
public struct hello
{
public int x;
public int y;
}
class Program
{
static void Main(string[] args)
{
hello h = new hello();
h.x = 1;
h.y = 2;
StringBuilder builder = new StringBuilder();
JsonFx.Json.JsonWriter r = new JsonFx.Json.JsonWriter(builder);
System.Security.Cryptography.MD5 md5 = System.Security.Cryptography.MD5.Create();
r.Write(h);
Console.WriteLine(builder.ToString());
string decrypt = EncryptString(builder.ToString());
Console.WriteLine(decrypt);
string encrypt = DecryptString(decrypt);
Console.WriteLine(encrypt);
}
private static string DecryptString(string Message)
{
byte[] buffer;
UTF8Encoding encoding = new UTF8Encoding();
MD5CryptoServiceProvider provider = new MD5CryptoServiceProvider();
byte[] buffer2 = provider.ComputeHash(encoding.GetBytes("$t611@"));
TripleDESCryptoServiceProvider provider2 = new TripleDESCryptoServiceProvider
{
Key = buffer2,
Mode = CipherMode.ECB,
Padding = PaddingMode.PKCS7
};
byte[] inputBuffer = Convert.FromBase64String(Message);
try
{
buffer = provider2.CreateDecryptor().TransformFinalBlock(inputBuffer, 0, inputBuffer.Length);
}
finally
{
provider2.Clear();
provider.Clear();
}
return encoding.GetString(buffer);
}
private static string EncryptString(string Message)
{
byte[] buffer;
UTF8Encoding encoding = new UTF8Encoding();
MD5CryptoServiceProvider provider = new MD5CryptoServiceProvider();
byte[] buffer2 = provider.ComputeHash(encoding.GetBytes("$t611@"));
TripleDESCryptoServiceProvider provider2 = new TripleDESCryptoServiceProvider
{
Key = buffer2,
Mode = CipherMode.ECB,
Padding = PaddingMode.PKCS7
};
byte[] bytes = encoding.GetBytes(Message);
try
{
buffer = provider2.CreateEncryptor().TransformFinalBlock(bytes, 0, bytes.Length);
}
finally
{
provider2.Clear();
provider.Clear();
}
return Convert.ToBase64String(buffer);
}
}
}
一段Untiy3d数据加密解密的代码
最新推荐文章于 2024-06-13 09:00:00 发布