RSA、AES、DES速度比较

引用库 Unity_RSA_DES

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}");
        }
    }
}

输出结果:
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/WGYHAPPY/article/details/129853420
今日推荐