'팁&테크/C# & Unity3D'에 해당되는 글 2건
- 2015.10.12 AES CBC 128BIT PKCS5 암/복호화(C#)
- 2015.10.07 유니티 플랫폼별 경로
AES CBC 128BIT PKCS5 암/복호화(C#)
using UnityEngine; using System; using System.Text; using System.IO; using System.Security.Cryptography; using System.Runtime.Remoting.Metadata.W3cXsd2001; public class Crypto { public static readonly string key = MD5Hash("암호키"); public static readonly string iv = MD5Hash("iv키"); public static string MD5Hash(string str) { MD5 md5 = new MD5CryptoServiceProvider(); byte[] hash = md5.ComputeHash(Encoding.ASCII.GetBytes(str)); StringBuilder stringBuilder = new StringBuilder(); foreach (byte b in hash) { stringBuilder.AppendFormat("{0:x2}", b); } return stringBuilder.ToString(); } private static byte[] GetBytesFromHexString(string strInput) { byte[] bytArOutput = new byte[] { }; if ((!string.IsNullOrEmpty(strInput)) && strInput.Length % 2 == 0) { SoapHexBinary hexBinary = null; hexBinary = SoapHexBinary.Parse(strInput); bytArOutput = hexBinary.Value; } return bytArOutput; } //AES 암호화 public static string AES128Encrypt(string Input) { try { RijndaelManaged aes = new RijndaelManaged(); //aes.KeySize = 256; //AES256으로 사용시 aes.KeySize = 128; //AES128로 사용시 aes.BlockSize = 128; aes.Mode = CipherMode.CBC; aes.Padding = PaddingMode.PKCS7; aes.Key = GetBytesFromHexString(key); aes.IV = GetBytesFromHexString(iv); var encrypt = aes.CreateEncryptor(aes.Key, aes.IV); byte[] xBuff = null; using (var ms = new MemoryStream()) { using (var cs = new CryptoStream(ms, encrypt, CryptoStreamMode.Write)) { byte[] xXml = Encoding.UTF8.GetBytes(Input); cs.Write(xXml, 0, xXml.Length); } xBuff = ms.ToArray(); } string Output = Convert.ToBase64String(xBuff); return Output; } catch (Exception ex) { Debug.LogError(ex.Message); return ex.Message; } } //AES 복호화 public static string AES128Decrypt(string Input) { try { RijndaelManaged aes = new RijndaelManaged(); //aes.KeySize = 256; //AES256으로 사용시 aes.KeySize = 128; //AES128로 사용시 aes.BlockSize = 128; aes.Mode = CipherMode.CBC; aes.Padding = PaddingMode.PKCS7; aes.Key = GetBytesFromHexString(key); aes.IV = GetBytesFromHexString(iv); var decrypt = aes.CreateDecryptor(); byte[] xBuff = null; using (var ms = new MemoryStream()) { using (var cs = new CryptoStream(ms, decrypt, CryptoStreamMode.Write)) { byte[] xXml = Convert.FromBase64String(Input); cs.Write(xXml, 0, xXml.Length); } xBuff = ms.ToArray(); } string Output = Encoding.UTF8.GetString(xBuff); return Output; } catch (Exception ex) { Debug.LogError(ex.Message); return string.Empty; } } }
유니티 플랫폼별 경로
Editor
- Application.dataPath /*project*/Assets
Web Player
System.IO.Path.GetFullPath(".") | %Project% |
Application.dataPath | %Project%/Assets |
Application.persistentDataPath | %userprofile%\AppData\LocalLow/%Company%/%Product% |
Application.streamingAssetsPath | %Project%/Assets/StreamingAssets |
Application.temporaryCachePath | %LocalAppData%/Local/Temp/Temp/%Company%/%Product% |
Android
System.IO.Path.GetFullPath(".") | / |
Application.dataPath | /data/app/%BundleIdentifier%.apk |
Application.persistentDataPath | /data/data/%BundleIdentifier%/files |
Application.streamingAssetsPath | jar:file:///data/app/%BundleIdentifier%.apk/!/assets |
Application.temporaryCachePath | /data/data/%BundleIdentifier%/cache |
Android sdcard
Application.persistentDataPath | /mnt/sdcard/Android/data/%BundleIdentifier%/files |
Application.streamingAssetsPath | jar:file:///data/app/%BundleIdentifier%.apk/!/assets |
Application.temporaryCachePathz | /mnt/sdcard/Android/data/%BundleIdentifier%/cache |
iOS
System.IO.Path.GetFullPath(".") | / |
Application.dataPath | %ProvisioningProfile%/%BundleIdentifier%.app/Data |
Application.persistentDataPath | %ProvisioningProfile%/Documents |
Application.streamingAssetsPath | %ProvisioningProfile%/%BundleIdentifier%.app/Data/Raw |
Application.temporaryCachePath | %ProvisioningProfile%/Library/Caches |
// ** iPhone device
- Application.dataPath /var/mobile/Applications/XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX/Assets
- Application.persistentDataPath : /var/mobile/Applications/XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX/Documents
- Application.temporaryCachePath : /var/mobile/Applications/XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX/Library/Caches
- iPhpone Simulator Path : /Users/<Name>/Library/Application Support/iPhone Simulator/4.1/Applications/<GUID>/
// ** Android
- Application.dataPath /mnt/asec/com.xxx.xxx/pkg.apk
- Application.persistentDataPath /data/data/com.xxx.xxx/files/
- Application.temporaryCachePath /data/data/com.xxx.xxx/cache/
* sdcard 사용시.
- Application.persistentDataPath /mnt/sdcard/Android/data/com.xxx.xxx/files/
- Application.temporaryCachePath /mnt/sdcard/Android/data/com.xxx.xxx/cache/