培训考核三期,新版培训,网页版培训登录器
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

78 lines
3.0 KiB

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class RSAHelper : MonoBehaviour
{
private const string privateKey = "ANXINxf119!@";
//public string message = "xf119119!@我";
//private string msgAdd = "";
//private string msgDel = "";
void Start()
{
}
// Update is called once per frame
void Update()
{
//if (Input.GetKeyDown(KeyCode.T))
//{
// TipPanelManager.GetInstance.Show("ceshitongguo");
//}
//if (Input.GetKeyDown(KeyCode.S))
//{
// WWW www = new WWW("https://www.baidu.com/");
// Application.OpenURL(www.url);
//}
//if (Input.GetKeyDown(KeyCode.Q))
//{
// msgAdd = RSAEncryption(message, privateKey);
// Debug.Log("加密后信息:" + msgAdd);
//}
//if (Input.GetKeyDown(KeyCode.W))
//{
// msgDel = RSADecrypt(msgAdd, privateKey);
// Debug.Log("解密后信息:" + msgDel);
//}
}
/// <summary>
/// RSA加密数据
/// </summary>
/// <param name="express">要加密数据</param>
/// <param name="KeyContainerName">密匙容器的名称</param>
/// <returns></returns>
public static string RSAEncryption(string express, string KeyContainerName = null)
{
System.Security.Cryptography.CspParameters param = new System.Security.Cryptography.CspParameters();
param.KeyContainerName = KeyContainerName ?? privateKey; //密匙容器的名称,保持加密解密一致才能解密成功
using (System.Security.Cryptography.RSACryptoServiceProvider rsa = new System.Security.Cryptography.RSACryptoServiceProvider(param))
{
byte[] plaindata = System.Text.Encoding.Default.GetBytes(express);//将要加密的字符串转换为字节数组
byte[] encryptdata = rsa.Encrypt(plaindata, false);//将加密后的字节数据转换为新的加密字节数组
return Convert.ToBase64String(encryptdata);//将加密后的字节数组转换为字符串
}
}
/// <summary>
/// RSA解密数据
/// </summary>
/// <param name="express">要解密数据</param>
/// <param name="KeyContainerName">密匙容器的名称</param>
/// <returns></returns>
public static string RSADecrypt(string ciphertext, string KeyContainerName = null)
{
System.Security.Cryptography.CspParameters param = new System.Security.Cryptography.CspParameters();
param.KeyContainerName = KeyContainerName ?? privateKey; //密匙容器的名称,保持加密解密一致才能解密成功
using (System.Security.Cryptography.RSACryptoServiceProvider rsa = new System.Security.Cryptography.RSACryptoServiceProvider(param))
{
byte[] encryptdata = Convert.FromBase64String(ciphertext);
byte[] decryptdata = rsa.Decrypt(encryptdata, false);
return System.Text.Encoding.Default.GetString(decryptdata);
}
}
}