[/font]
using
System.Collections;
using
System.Text;
using
System.Security.Cryptography;
using
System;
[font=黑体]
public
class
ADDJIEMI : MonoBehaviour [/font][font=黑体]{
public
UIInput _input;
private
string
inputText;
private
string
strEncryption;
private
string
strkeyValue;
void
Start()
{
strkeyValue =
"12345678901234567890198915689039"
;
}
public
void
encryptionClick()
{
inputText = _input.value;
strEncryption=encryptionContent(inputText, strkeyValue);
Debug.Log(strEncryption);
}
public
void
decipherClick()
{
inputText = decipheringContent(strEncryption, strkeyValue);
Debug.Log(inputText);
}
/// <summary>
/// 内容加密
/// </summary>
/// <param name="ContentInfo">要加密内容</param>
/// <param name="strkey">key值</param>
/// <returns></returns>
public
string
encryptionContent(
string
ContentInfo,
string
strkey)
{
byte
[] keyArray = UTF8Encoding.UTF8.GetBytes(strkey);
RijndaelManaged encryption =
new
RijndaelManaged();
encryption.Key = keyArray;
encryption.Mode = CipherMode.ECB;
encryption.Padding = PaddingMode.PKCS7;
ICryptoTransform cTransform = encryption.CreateEncryptor();
byte
[] _EncryptArray = UTF8Encoding.UTF8.GetBytes(ContentInfo);
byte
[] resultArray = cTransform.TransformFinalBlock(_EncryptArray, 0, _EncryptArray.Length);
return
Convert.ToBase64String(resultArray, 0, resultArray.Length);
}
/// <summary>
/// 内容解密
/// </summary>
/// <param name="encryptionContent">被加密内容</param>
/// <param name="strkey">key值</param>
/// <returns></returns>
public
string
decipheringContent(
string
encryptionContent,
string
strkey)
{
byte
[] keyArray = UTF8Encoding.UTF8.GetBytes(strkey);
RijndaelManaged decipher =
new
RijndaelManaged();
decipher.Key = keyArray;
decipher.Mode = CipherMode.ECB;
decipher.Padding = PaddingMode.PKCS7;
ICryptoTransform cTransform = decipher.CreateDecryptor();
byte
[] _EncryptArray = Convert.FromBase64String(encryptionContent);
byte
[] resultArray = cTransform.TransformFinalBlock(_EncryptArray, 0, _EncryptArray.Length);
return
UTF8Encoding.UTF8.GetString(resultArray);
}
}