Beispiel #1
0
    public static byte[] EncryptByte(byte[] binData, string key)
    {
        // Rijndaelアルゴリズム暗号化オブジェクトの作成
        RijndaelManaged aes = new RijndaelManaged();

        aes.Padding = PaddingMode.Zeros;
        aes.Mode    = CipherMode.CBC;

        // 共有キーと初期化ベクタを決定
        // パスワードをバイト配列にする
        byte[] bytesKey = Encoding.UTF8.GetBytes(key);

        // 共有キーと初期化ベクタを設定
        aes.Key = CryptInformation.ResizeBytesArray(bytesKey, aes.Key.Length);
        aes.IV  = CryptInformation.ResizeBytesArray(bytesKey, aes.IV.Length);

        ICryptoTransform encryptor = aes.CreateEncryptor();

        MemoryStream msEncrypt = new MemoryStream();
        CryptoStream csEncrypt = new CryptoStream(msEncrypt, encryptor, CryptoStreamMode.Write);

        byte[] src = binData;

        // 暗号化する
        csEncrypt.Write(src, 0, src.Length);
        csEncrypt.FlushFinalBlock();

        byte[] dest = msEncrypt.ToArray();

        return(dest);
    }
Beispiel #2
0
    /// <summary>
    /// 複合化スクリプト
    /// </summary>
    /// <returns>byte[] 複合化したbyte列</returns>
    public static byte[] DecryptByte(byte[] binData, string key)
    {
        RijndaelManaged aes = new RijndaelManaged();

        aes.Padding = PaddingMode.Zeros;
        aes.Mode    = CipherMode.CBC;

        // 共有キーと初期化ベクタを決定
        // パスワードをバイト配列にする
        byte[] bytesKey = Encoding.UTF8.GetBytes(key);

        // 共有キーと初期化ベクタを設定
        aes.Key = CryptInformation.ResizeBytesArray(bytesKey, aes.Key.Length);
        aes.IV  = CryptInformation.ResizeBytesArray(bytesKey, aes.IV.Length);

        ICryptoTransform decryptor = aes.CreateDecryptor();

        byte[] src  = binData;
        byte[] dest = new byte[src.Length];

        MemoryStream msDecrypt = new MemoryStream(src);
        CryptoStream csDecrypt = new CryptoStream(msDecrypt, decryptor, CryptoStreamMode.Read);

        // 複号化する
        csDecrypt.Read(dest, 0, dest.Length);

        return(dest);
    }
        private IEnumerator DisplayNews(string result)
        {
            const float interval = 1f;

            if (string.IsNullOrEmpty(result) == true)
            {
                yield break;
            }

            //jsonを復号化
            string decjson = CryptInformation.DecryptString(result, CommonConst.CryptKey.DecNews);

            T_RLU_NewsHistory model = JsonMapper.ToObject <T_RLU_NewsHistory>(decjson);

            if (CommonFunction.IsNull(model) == true)
            {
                yield break;
            }

            NewsNumber = model.iSequence;

            if (IsFirst == true)
            {
                IsFirst = false;
                yield break;
            }

            NewsText.text = CreateNews(model);

            float time = 0;

            //だんだん明るく
            time = 0;
            while (time <= interval)
            {
                cvGroup.alpha = Mathf.Clamp((time / interval), 0f, 1f);

                time += CommonFunction.GetDelta(1);
                yield return(null);
            }

            time = 0;
            //5秒待つ
            while (time <= 5)
            {
                time += CommonFunction.GetDelta(1);
                yield return(null);
            }

            //だんだん暗く
            time = 0;
            while (time <= interval)
            {
                cvGroup.alpha = Mathf.Clamp(1 - (time / interval), 0f, 1f);
                time         += CommonFunction.GetDelta(1);
                yield return(null);
            }

            cvGroup.alpha = 0;
        }
    private static T LoadCommon <T>(string keyskey, string valueskey, string encKey)
    {
        try
        {
            //キーと値を取得
            string key   = PlayerPrefs.GetString(keyskey);
            string value = PlayerPrefs.GetString(valueskey);

            if (string.IsNullOrEmpty(key) == false && string.IsNullOrEmpty(value) == false)
            {
                //キーを復号化
                string deckey = CryptInformation.DecryptString(key, encKey);

                //値を復号化
                string decvalue = CryptInformation.DecryptString(value, deckey);

                return(JsonMapper.ToObject <T>(decvalue));
            }
            else
            {
                PlayerPrefs.DeleteKey(keyskey);
                PlayerPrefs.DeleteKey(valueskey);
                return(default(T));
            }
        }
        //エラーが発生したらnull
        catch (Exception)
        {
            PlayerPrefs.DeleteKey(SystemValueKey);
            PlayerPrefs.DeleteKey(SystemValueValue);
            PlayerPrefs.Save();
            return(default(T));
        }
    }
    public IEnumerator SendLogCorutine(Exception e, string state)
    {
        if (IsOneTime == true)
        {
            yield break;
        }

        IsOneTime = true;


        string otp = CommonConst.CryptKey.ErrorLog;

        T_RLU_ErrorLog el = new T_RLU_ErrorLog();

#if UNITY_EDITOR
        el.vcVersion = "0.01";
#else
        el.vcVersion = CommonConst.SystemValue.CurrentVersion;
#endif
        el.vcException  = CommonFunction.CutString(e.GetType().ToString(), 100);
        el.vcMessage    = CommonFunction.CutString(e.Message, 200);
        el.vcStackTrace = CommonFunction.CutString(state + e.StackTrace, 4000);


        string json = JsonMapper.ToJson(el);

        //OTPを使ってリソース名を暗号化
        string ecjson = CryptInformation.EncryptString(json, otp);

        Dictionary <string, string> headers = new Dictionary <string, string>();

//#if UNITY_EDITOR
//        sessionid = sessionid.Replace("ASP.NET_SessionId=", "");
//        Regex rgx = new Regex(";.+");
//        sessionid = rgx.Replace(sessionid, "");
//        headers.Add("Cookie", string.Format("ASP.NET_SessionId={0};", sessionid));
//#endif

        WWWForm form = new WWWForm();
        form.AddField("input", ecjson);

#if UNITY_EDITOR
        WWW www = new WWW(UrlRes, form.data, headers);
#else
        headers = form.headers;
        headers.Add("Access-Control-Allow-Credentials", "true");
        headers.Add("Access-Control-Allow-Headers", "Accept");
        headers.Add("Access-Control-Allow-Methods", "POST");
        headers.Add("Access-Control-Allow-Origin", "*");
        WWW www = new WWW(UrlRes, form.data, headers);
#endif

        while (www.isDone == false && www.progress != 1)
        {
            yield return(null);
        }
        www.Dispose();
    }
Beispiel #6
0
    public static byte[] DecryptFile(string inputFile, string outputFile, string key)
    {
        // バイナリ・ファイルの読み込み
        byte[] src = File.ReadAllBytes(inputFile);

        byte[] result = CryptInformation.DecryptByte(src, key);

        File.WriteAllBytes(outputFile, result);

        return(result);
    }
    private static void SaveCommon(string keyskey, string valueskey, string encKey, string jsondata)
    {
        //保存キーの発行
        string key = Guid.NewGuid().ToString("D");

        //データを暗号化
        string value = CryptInformation.EncryptString(jsondata, key);

        //キーを暗号化
        string enckey = CryptInformation.EncryptString(key, encKey);

        //データとキーを保存
        PlayerPrefs.SetString(keyskey, enckey);
        PlayerPrefs.SetString(valueskey, value);
    }
Beispiel #8
0
    /// <summary>
    /// 文字列を暗号化する
    /// </summary>
    /// <param name="target">暗号化する文字列</param>
    /// <returns>暗号化された文字列</returns>
    public static string EncryptString(string target, string key)
    {
        // NULLか空文字の場合はそのまま返す
        if (string.IsNullOrEmpty(target) == true)
        {
            return(target);
        }

        // 文字列をバイト型配列にする
        byte[] bytesIn = Encoding.UTF8.GetBytes(target);
        byte[] bytesOut;

        // Rijndaelアルゴリズム暗号化オブジェクトの作成
        RijndaelManaged aes = new RijndaelManaged();

        // 共有キーと初期化ベクタを決定
        // パスワードをバイト配列にする
        byte[] bytesKey = Encoding.UTF8.GetBytes(key);

        // 共有キーと初期化ベクタを設定
        aes.Key = CryptInformation.ResizeBytesArray(bytesKey, aes.Key.Length);
        aes.IV  = CryptInformation.ResizeBytesArray(bytesKey, aes.IV.Length);

        // 暗号化オブジェクトの作成
        ICryptoTransform desdecrypt = aes.CreateEncryptor();

        // 暗号化されたデータを書き出すためのMemoryStream
        using (MemoryStream msOut = new MemoryStream())
            // 書き込むためのCryptoStreamの作成
            using (CryptoStream cryptStreem = new CryptoStream(msOut, desdecrypt, CryptoStreamMode.Write))
            {
                // 書き込む
                cryptStreem.Write(bytesIn, 0, bytesIn.Length);
                cryptStreem.FlushFinalBlock();

                // 暗号化されたデータを取得
                bytesOut = msOut.ToArray();

                // 閉じる
                cryptStreem.Close();
                msOut.Close();
            }

        // Base64で文字列に変更して結果を返す
        return(Convert.ToBase64String(bytesOut));
    }
Beispiel #9
0
    /// <summary>
    /// 暗号化された文字列を復号化する
    /// </summary>
    /// <param name="target">暗号化された文字列</param>
    /// <returns>復号化された文字列</returns>
    public static string DecryptString(string target, string key)
    {
        string result = null;

        // NULLか空文字の場合はそのまま返す
        if (string.IsNullOrEmpty(target) == true)
        {
            return(target);
        }

        // Rijndaelアルゴリズム暗号化オブジェクトの作成
        RijndaelManaged aes = new RijndaelManaged();

        // 共有キーと初期化ベクタを決定
        // パスワードをバイト配列にする
        byte[] bytesKey = Encoding.UTF8.GetBytes(key);

        // 共有キーと初期化ベクタを設定
        aes.Key = CryptInformation.ResizeBytesArray(bytesKey, aes.Key.Length);
        aes.IV  = CryptInformation.ResizeBytesArray(bytesKey, aes.IV.Length);

        // Base64で文字列をバイト配列に戻す
        byte[] bytesIn = Convert.FromBase64String(target);

        // 復号化オブジェクトの作成
        ICryptoTransform desdecrypt = aes.CreateDecryptor();

        // 暗号化されたデータを読み込むためのMemoryStream
        using (MemoryStream msIn = new MemoryStream(bytesIn))
            // 読み込むためのCryptoStreamの作成
            using (CryptoStream cryptStreem = new CryptoStream(msIn, desdecrypt, CryptoStreamMode.Read))
                // 復号化されたデータを取得するためのStreamReader
                using (StreamReader srOut = new StreamReader(cryptStreem, Encoding.UTF8))
                {
                    // 復号化されたデータを取得する
                    result = srOut.ReadToEnd();
                }

        return(result);
    }
    private IEnumerator CheckStartup()
    {
#if UNITY_EDITOR
        const string UrlRes = @"http://*****:*****@"http://localhost:60860/Resource/IssueStart";
#else
        const string UrlRes = @"http://custom-sb.azurewebsites.net/Resource/Start";
        const string UrlOTP = @"http://custom-sb.azurewebsites.net/Resource/IssueStart";
#endif

        //OTPを取得
        WWW www = new WWW(UrlOTP);

        while (www.isDone == false && www.progress != 1)
        {
            yield return(null);
        }
        yield return(www);

        if (CommonFunction.IsNull(www.error) == false)
        {
            www.Dispose();
            yield break;
        }


        string rowotp = www.text;

        string sessionid = null;
#if UNITY_EDITOR
        sessionid = www.responseHeaders["SET-COOKIE"];
#endif
        www.Dispose();

        //OTPを復号化
        string otp = CryptInformation.DecryptString(rowotp, CommonConst.CryptKey.StartOTP);

        //OTPを使って実行キーを暗号化
        string ecjson = CryptInformation.EncryptString(CommonConst.Key.StartKey, otp);

        Dictionary <string, string> headers = new Dictionary <string, string>();

#if UNITY_EDITOR
        sessionid = sessionid.Replace("ASP.NET_SessionId=", "");
        Regex rgx = new Regex(";.+");
        sessionid = rgx.Replace(sessionid, "");
        headers.Add("Cookie", string.Format("ASP.NET_SessionId={0};", sessionid));
#endif

        WWWForm form = new WWWForm();
        form.AddField("input", ecjson);

#if UNITY_EDITOR
        www = new WWW(UrlRes, form.data, headers);
#else
        headers = form.headers;
        headers.Add("Access-Control-Allow-Credentials", "true");
        headers.Add("Access-Control-Allow-Headers", "Accept");
        headers.Add("Access-Control-Allow-Methods", "POST");
        headers.Add("Access-Control-Allow-Origin", "*");
        www = new WWW(UrlRes, form.data, headers);
#endif

        while (www.isDone == false && www.progress != 1)
        {
            yield return(null);
        }

        yield return(www);

        string dec = CryptInformation.DecryptString(www.text, CommonConst.CryptKey.StartCrypt);

        if (dec == CommonConst.Key.StartExeKey)
        {
            IsStart = true;
        }

        www.Dispose();
    }
    public IEnumerator SendScoreCorutine(string json)
    {
#if UNITY_EDITOR
        const string UrlRes = @"http://*****:*****@"http://localhost:60860/Resource/IssueSC";
        //const string UrlRes = @"http://custom-sb.azurewebsites.net/Resource/SCR";
        //const string UrlOTP = @"http://custom-sb.azurewebsites.net/Resource/IssueSC";
#else
        //const string UrlRes = @"http://custom-sb.azurewebsites.net/Resource/SCR";
        //const string UrlOTP = @"http://custom-sb.azurewebsites.net/Resource/IssueSC";
        const string UrlRes = @"http://custom-sb-rc.azurewebsites.net/Resource/SCR";
        const string UrlOTP = @"http://custom-sb-rc.azurewebsites.net/Resource/IssueSC";
#endif

        //OTPを取得
        //        WWW www = new WWW(UrlOTP);

        //        while (www.isDone == false && www.progress != 1)
        //        {
        //            yield return null;
        //        }

        //        if (CommonFunction.IsNull(www.error) == false)
        //        {
        //            www.Dispose();
        //            yield break;
        //        }

        //        string rowotp = www.text;

        //        string sessionid = null;
        //#if UNITY_EDITOR
        //        sessionid = www.responseHeaders["SET-COOKIE"];
        //#endif
        //        www.Dispose();

        //        //OTPを復号化
        //        string otp = CryptInformation.DecryptString(rowotp, CommonConst.CryptKey.SCOTP);

        //        //OTPを使ってリソース名を暗号化
        //        string ecjson = CryptInformation.EncryptString(json, otp);
        string ecjson = CryptInformation.EncryptString(json, CommonConst.CryptKey.SCOTP);

        Dictionary <string, string> headers = new Dictionary <string, string>();

#if UNITY_EDITOR
        //sessionid = sessionid.Replace("ASP.NET_SessionId=", "");
        //Regex rgx = new Regex(";.+");
        //sessionid = rgx.Replace(sessionid, "");
        //headers.Add("Cookie", string.Format("ASP.NET_SessionId={0};", sessionid));
#endif

        WWWForm form = new WWWForm();
        form.AddField("input", ecjson);

#if UNITY_EDITOR
        WWW www = new WWW(UrlRes, form.data, headers);
#else
        headers = form.headers;
        headers.Add("Access-Control-Allow-Credentials", "true");
        headers.Add("Access-Control-Allow-Headers", "Accept");
        headers.Add("Access-Control-Allow-Methods", "POST");
        headers.Add("Access-Control-Allow-Origin", "*");
        WWW www = new WWW(UrlRes, form.data, headers);
#endif

        while (www.isDone == false && www.progress != 1)
        {
            yield return(null);
        }
        www.Dispose();
    }
        private IEnumerator CheckNews()
        {
            T_RLU_NewsHistory input = new T_RLU_NewsHistory();

            input.iSequence = NewsNumber;
            input.vcVersion = CommonConst.SystemValue.CurrentVersion;
            input.vcGameId  = GameStateInformation.GameId.ToString("D");

            string json = JsonMapper.ToJson(input);
            //jsonを暗号化
            string ecjson = CryptInformation.EncryptString(json, CommonConst.CryptKey.GetNews);

            //ニュースを取得
            Dictionary <string, string> headers = new Dictionary <string, string>();

#if UNITY_EDITOR
            //sessionid = sessionid.Replace("ASP.NET_SessionId=", "");
            //Regex rgx = new Regex(";.+");
            //sessionid = rgx.Replace(sessionid, "");
            //headers.Add("Cookie", string.Format("ASP.NET_SessionId={0};", sessionid));
#endif

            WWWForm form = new WWWForm();
            form.AddField("input", ecjson);

#if UNITY_EDITOR
#else
            headers = form.headers;
            headers.Add("Access-Control-Allow-Credentials", "true");
            headers.Add("Access-Control-Allow-Headers", "Accept");
            headers.Add("Access-Control-Allow-Methods", "POST");
            headers.Add("Access-Control-Allow-Origin", "*");
#endif

            //WWW www = new WWW(UrlNews, form.data, headers);

            //while (www.isDone == false && www.progress != 1)
            //{
            //    yield return null;
            //}
            //yield return www;

            var www = ObservableWWW.Post(UrlNews, form.data, headers).ToYieldInstruction();
            while (!(www.HasResult || www.IsCanceled || www.HasError)) // 3つもプロパティ並べるのダルいので次回アップデートでIsDoneを追加します予定
            {
                yield return(null);
            }

            string result = "";
            if (www.HasResult == true && CommonFunction.IsNullOrWhiteSpace(www.Result) == false)
            {
                result = www.Result;
            }

            //if(CommonFunction.IsNullOrWhiteSpace(www.error) == true)
            //{
            //    result = www.text;
            //}

            www.Dispose();

            yield return(null);

            //yield return Observable.FromMicroCoroutine(() => DisplayNews(result)).Subscribe();
            MainThreadDispatcher.StartUpdateMicroCoroutine(DisplayNews(result));
            //yield return  StartCoroutine(DisplayNews(result));

            NewsCheckCoroutine = null;
        }