|
@@ -0,0 +1,43 @@
|
|
|
+using System;
|
|
|
+using System.Diagnostics;
|
|
|
+using System.IO;
|
|
|
+using System.Security.Cryptography;
|
|
|
+using System.Text;
|
|
|
+using UnityEngine;
|
|
|
+
|
|
|
+public class AESCrypto
|
|
|
+{
|
|
|
+ private static readonly string AES_KEY = "7b5a4d3e2f1c0b0a"; // 确保使用与 Java 中生成的密钥相同
|
|
|
+
|
|
|
+ public static string Decrypt(string encryptedData)
|
|
|
+ {
|
|
|
+ byte[] combinedData = Convert.FromBase64String(encryptedData);
|
|
|
+ byte[] iv = new byte[16]; // 128 位 AES 的 IV 长度
|
|
|
+ byte[] cipherText = new byte[combinedData.Length - iv.Length];
|
|
|
+
|
|
|
+ Array.Copy(combinedData, 0, iv, 0, iv.Length);
|
|
|
+ Array.Copy(combinedData, iv.Length, cipherText, 0, cipherText.Length);
|
|
|
+
|
|
|
+ using (Aes aes = Aes.Create())
|
|
|
+ {
|
|
|
+ aes.Key = Encoding.UTF8.GetBytes(AES_KEY);
|
|
|
+ aes.IV = iv;
|
|
|
+
|
|
|
+ using (ICryptoTransform decryptor = aes.CreateDecryptor(aes.Key, aes.IV))
|
|
|
+ using (MemoryStream ms = new MemoryStream(cipherText))
|
|
|
+ using (CryptoStream cs = new CryptoStream(ms, decryptor, CryptoStreamMode.Read))
|
|
|
+ using (StreamReader sr = new StreamReader(cs))
|
|
|
+ {
|
|
|
+ return sr.ReadToEnd();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 测试
|
|
|
+ public static void Test()
|
|
|
+ {
|
|
|
+ string encryptedData = "lVqQnIvDq9OhO74MsEOLFCHwBa6n/sS2Voa6iWbbPunKJ4FVsLgU7GZCfEuvOVALTLW0k7/UyNjNQlOJ0B6QUZb+0IrJRK7g4CLEoPuhWTmeberYVfMNRFecesxt2IsttSWecqLtngVGJ5nOmTRTeJnum11GON8PAZTz85BLlLjOvOPpzw6oIcBrsqu6qu8UMW9BrjOuH4elg6zInmZxOlLOIMgTYwcc0lkWEb7RvEUrCGKC4DYnUI1s86iXKTvLrxIjB3WAcoyRcllAc7Tl4JWezUJ4kW3dPNaFSKb2JUncYPR+RR9iv3vUeLffQWPWSVesSjD/PsUXU1SQrjfSruO5sbRo33+plerlUv5Gm5iHrgXTrWILoMHomOz1Hv3HGkEODgIakOCP6SflVznfPxSFXa9tSLwQcV/2+p4SLBc8x9dNEsdh0TwHrwQ2eeNLBaHkoXGNg7Tg3Qh0WRrtiMhwEvydp7VNZBFKsdeQjRRlzsXZsgl/dP706//tw0Ze4KHGD6cf/RpZK5nWgWpjEjZfQseA4UJUU12hQq6iD8LE5ZL/swiVxUJf9fsRk9xs"; // 从 Java 获取的加密数据
|
|
|
+ string decryptedData = Decrypt(encryptedData);
|
|
|
+ UnityEngine.Debug.Log("Decrypted: " + decryptedData);
|
|
|
+ }
|
|
|
+}
|