using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using UnityEngine;
using Debug = UnityEngine.Debug;
namespace LZGood
{
public class AlgorithmCompare : MonoBehaviour
{
private void Start()
{
var path = Application.streamingAssetsPath + "/RSA/";
var privateKey = File.ReadAllText(path + "privateKey.xml");
var publicKey = File.ReadAllText(path + "publicKey.xml");
string message = "Hello the World!";
Debug.Log("encrypt and decrypt message: " + message);
Stopwatch stopwatch = new Stopwatch();
stopwatch.Restart();
byte[] data = Encoding.Default.GetBytes(message);
byte[] encryptData = RSAHelper.Encrypt(data, publicKey);
byte[] decryptData = RSAHelper.Decrypt(encryptData, privateKey);
stopwatch.Stop();
Debug.Log($"Time Of RSA : {
stopwatch.ElapsedMilliseconds} ms, {
Encoding.Default.GetString(decryptData)}");
stopwatch.Restart();
var aesEncrypt1 = SDKSecurity.AESEncrypt(message, "anson-xu");
var data1 = SDKSecurity.AESDecrypt(aesEncrypt1, "anson-xu");
stopwatch.Stop();
Debug.Log($"Time Of AES: {
stopwatch.ElapsedMilliseconds} ms, {
data1}");
stopwatch.Restart();
var desEncrypt2 = SDKSecurity.DESEncrypt(message, "anson-xu");
var data2 = SDKSecurity.DESDecrypt(desEncrypt2, "anson-xu");
stopwatch.Stop();
Debug.Log($"Time Of DES: {
stopwatch.ElapsedMilliseconds} ms, {
data2}");
}
}
}
输出结果: