'RSA'에 해당되는 글 1건

  1. 2015/01/20 글뻥 유니티 3D RSA 방식 암복호화
출처는 이전의 AES 방식(링크 : http://www.wolfpack.pe.kr/828) 과 같이.. 까먹었슴돠..

using UnityEngine;
using System.Collections;
using System.Security.Cryptography;
using System.Text;

public class MainTester : MonoBehaviour {

 string _x = "";
 UTF8Encoding ByteConv = new UTF8Encoding();
 RSACryptoServiceProvider RSA = new RSACryptoServiceProvider();
 
 // Use this for initialization
 void Start () {
 _x = "Hello!!!";
 byte[] _encText = Encryption(ByteConv.GetBytes(_x), RSA.ExportParameters(false), false);
 Debug.Log( ByteConv.GetString(_encText) );
 Debug.Log(ByteConv.GetString(Decryption(_encText, RSA.ExportParameters(true), false)));
 }
 
 static public byte[] Encryption(byte[] Data, RSAParameters RSAKey, bool DoOAEPPadding)
 {
 try
 {
 byte[] encryptedData;
 using (RSACryptoServiceProvider RSA = new RSACryptoServiceProvider())
 {
 RSA.ImportParameters(RSAKey);
 encryptedData = RSA.Encrypt(Data, DoOAEPPadding);
 }
 return encryptedData;
 }
 catch (CryptographicException e)
 {
 Debug.Log(e.Message);
 return null;
 }
 }

 static public byte[] Decryption(byte[] Data, RSAParameters RSAKey, bool DoOAEPPadding)
 {
 try
 {
 byte[] decryptedData;
 using (RSACryptoServiceProvider RSA = new RSACryptoServiceProvider())
 {
 RSA.ImportParameters(RSAKey);
 decryptedData = RSA.Decrypt(Data, DoOAEPPadding);
 }
 return decryptedData;
 }
 catch (CryptographicException e)
 {
 Debug.Log(e.ToString());
 return null;
 }
 }
}


암호화 결과 : 0BB@�{8n��*�b"�FN?s�
복호화 결과 : Hello!!!
2015/01/20 15:40 2015/01/20 15:40