Unity 㧠SHA1(ã¡ãã»ã¼ã¸ãã¤ã¸ã§ã¹ã) ãçæããæ¹æ³
ã¾ãã¯æ¤è¨¼ç¨ã®ãã¼ã¿ã PHP ã§ä½æã以ä¸ã®ã³ãã³ããå®è¡ã
php -r 'echo sha1("apple")."\n";'
çµæã¯ãã¡ãã¯
d0be2dc421be4fcd0172e5afceea3970e2f3d940
ã C# ã§ã®ãµã³ãã«ã
â»ãã¤ããªã®ã¾ã¾ã ã¨ç»é¢ã«è¡¨ç¤ºåºæ¥ãªãã®ã§BASE64ã«å¤æ´ãã¦ãã¾ãã
using UnityEngine; using System.Collections; using System.Text; using System.Security.Cryptography; public class MyGUI : MonoBehaviour { string txt = ""; void OnGUI () { GUI.TextField(new Rect(10, 10, 400, 50), txt); if (GUI.Button(new Rect(10, 70, 200, 100), "convert")) { SHA1 sha = new SHA1CryptoServiceProvider(); UTF8Encoding ue = new UTF8Encoding(); byte[] planeBytes = ue.GetBytes("apple"); byte[] hashBytes = sha.ComputeHash(planeBytes); string hashStr = ""; foreach(byte b in hashBytes) { hashStr += string.Format("{0,0:x2}", b); } txt = hashStr; } } }
å®è¡ããæã console ã«è¡¨ç¤ºãããæå㯠d0be2dc421be4fcd0172e5afceea3970e2f3d940 ãæ£ããã SHA1 ã§ããã·ã¥åãããå¤ãåå¾ã§ãã¾ããã
é¢é£æ å ±
Unity 㧠SHA256 ã使ãæ¹æ³ - å¼·ç«ã§é²ã
http://d.hatena.ne.jp/nakamura001/20120928/1348841124