Example #1
0
        /// <summary>
        /// get Md5 or normal filename
        /// </summary>
        /// <param name="fileName"></param>
        /// <returns></returns>
        public static string GetRightFileName(string fileName)
        {
            if (string.IsNullOrEmpty(fileName))
            {
                return(string.Empty);
            }

#if !HUGULA_COMMON_ASSETBUNDLE
            int lastFileIndex, lastDotIndex, fileLen, suffixLen;
            AnalysePathName(fileName, out lastFileIndex, out fileLen, out lastDotIndex, out suffixLen);

            string fname = fileName.Substring(lastFileIndex + 1, fileLen);
            string md5   = string.Empty;
            md5            = CryptographHelper.Md5String(fname);
            _textSB.Length = 0;
            _textSB.Append(fileName);
            if (fileLen > 0)
            {
                _textSB.Replace(fname, md5, lastFileIndex + 1, fileLen);
            }
            fname = _textSB.ToString();
            return(fname);
#else
            return(fileName);
#endif
        }
Example #2
0
        /// <summary>
        /// get Md5 or normal filename
        /// </summary>
        /// <param name="fileName"></param>
        /// <returns></returns>
        public static string GetRightFileName(string fileName)
        {
            if (string.IsNullOrEmpty(fileName))
            {
                return(string.Empty);
            }
            string fname = string.Empty;

            int lastFileIndex, lastDotIndex, fileLen, suffixLen;

            AnalysePathName(fileName, out lastFileIndex, out fileLen, out lastDotIndex, out suffixLen);
            if (lastFileIndex > 0)
            {
                fname = fileName.Substring(0, lastFileIndex + 1);
            }

#if BUILD_COMMON_ASSETBUNDLE
            fname += fileName.Substring(lastFileIndex + 1, fileLen);
#else
            fname += CryptographHelper.Md5String(fileName.Substring(lastFileIndex + 1, fileLen));
#endif
            if (suffixLen > 0)
            {
                fname += fileName.Substring(lastDotIndex, suffixLen);
            }
            return(fname);
        }
Example #3
0
        public static string LoadLocalData(string fileName)
        {
            string fullPath = CUtils.PathCombine(CUtils.GetRealPersistentDataPath(), fileName);

            if (System.IO.File.Exists(fullPath))
            {
                FileStream fs = new FileStream(fullPath, FileMode.Open);
                if (fs != null && fs.Length > 0)
                {
                    byte[] bytes = new byte[fs.Length];
                    fs.Read(bytes, 0, bytes.Length);
                    fs.Close();
                    string loadData = string.Empty;
                    try
                    {
                        loadData = Encoding.UTF8.GetString(CryptographHelper.Decrypt(bytes, key, iv));
                    }
                    catch (System.Exception ex)
                    {
                        Debug.LogError(ex);
                    }
                    return(loadData);
                }
            }
            return("");
        }
Example #4
0
    /// <summary>
    /// lua bundle
    /// </summary>
    /// <returns></returns>
    private IEnumerator loadLuaBundle(bool domain, LuaFunction onLoadedFn)
    {
        string keyName   = "";
        string luaP      = CUtils.GetAssetFullPath("font.u3d");
        WWW    luaLoader = new WWW(luaP);

        yield return(luaLoader);

        if (luaLoader.error == null)
        {
            byte[]      byts = CryptographHelper.Decrypt(luaLoader.bytes, DESHelper.instance.Key, DESHelper.instance.IV);
            AssetBundle item = AssetBundle.CreateFromMemoryImmediate(byts);

            TextAsset[] all = item.LoadAllAssets <TextAsset>();
            foreach (var ass in all)
            {
                keyName           = ass.name;
                luacache[keyName] = ass;
            }

            item.Unload(false);
            luaLoader.Dispose();
        }

        DoUnity3dLua();
        if (domain)
        {
            DoMain();
        }

        if (onLoadedFn != null)
        {
            onLoadedFn.Call();
        }
    }
Example #5
0
    private IEnumerator loadLuaBundle()
    {
        string keyName   = "";
        string luaPath   = PathUtil.GetAssetFullPath("lua.u3d");
        WWW    luaLoader = new WWW(luaPath);

        yield return(luaLoader);

        if (luaLoader.error == null)
        {
            byte[]      byts = CryptographHelper.Decrypt(luaLoader.bytes, KeyVData.Instance.KEY, KeyVData.Instance.IV);
            AssetBundle item = AssetBundle.LoadFromMemory(byts);
            TextAsset[] all  = item.LoadAllAssets <TextAsset>();
            foreach (TextAsset ass in all)
            {
                keyName           = ass.name;
                luacache[keyName] = ass.bytes;
            }

            item.Unload(true);
            luaLoader.Dispose();
        }

        DoMain();
    }
Example #6
0
        public static string LoadLocalData(string fileName)
        {
            string   fullPath = CUtils.PathCombine(CUtils.GetRealPersistentDataPath(), fileName);
            FileInfo fileInfo = new FileInfo(fullPath);
            string   loadData = string.Empty;

            if (fileInfo.Exists)
            {
                using (FileStream fs = fileInfo.OpenRead())
                {
                    byte[] bytes = new byte[fs.Length];
                    fs.Read(bytes, 0, bytes.Length);
                    try
                    {
                        loadData = Encoding.UTF8.GetString(CryptographHelper.Decrypt(bytes, key, iv));
                    }
                    catch (System.Exception ex)
                    {
                        Debug.LogError(ex);
                    }
                    return(loadData);
                }
            }
            return(loadData);
        }
        public void EncryptDataUsingTripleDES()
        {
            var encriptedText = CryptographHelper.TripleDESEncrypt(_textToEncrypt, _password);
            var decriptedText = CryptographHelper.TripleDESDecrypt(encriptedText, _password);

            Assert.IsNotNull(encriptedText);
            Assert.IsNotNull(decriptedText);
            Assert.AreEqual(_textToEncrypt, decriptedText);
        }
        public void EncryptDataUsingRijndael()
        {
            var encriptedText = CryptographHelper.RijndaelEncrypt(_textToEncrypt, _password);
            var decriptedText = CryptographHelper.RijndaelDecrypt(encriptedText, _password);

            Assert.IsNotNull(encriptedText);
            Assert.IsNotNull(decriptedText);
            Assert.AreEqual(_textToEncrypt, decriptedText);
        }
        public void EncryptAndDecryptDataUsingRSACertificate()
        {
            var certificate = new X509Certificate2(X509Certificate2.CreateFromSignedFile(_testCertificate));

            var encriptedText = CryptographHelper.RsaEncrypt(_textToEncrypt, certificate);
            var decriptedText = CryptographHelper.RsaDecrypt(encriptedText, certificate);

            Assert.IsNotNull(encriptedText);
            Assert.IsNotNull(decriptedText);
            Assert.AreEqual(_textToEncrypt, decriptedText);
        }
        public string GetEncryptedConnectionString(ConnectionStringFilterDTO filter)
        {
            var connectionString = string.Empty;

            try
            {
                if (string.IsNullOrEmpty(filter.ConnectionString))
                {
                    throw new ServiceException(CommonExceptionType.ParameterException, "ConnectionString");
                }

                var prefix = CommonResource.GetString("PassNumbers") + CommonResource.GetString("PassSpecialChars");
                var pass   = prefix + CommonResource.GetString("PassText") + prefix;

                var upperConnection = filter.ConnectionString.ToUpper();
                if (upperConnection.Contains("DATA SOURCE") &&
                    upperConnection.Contains("USER ID") &&
                    upperConnection.Contains("PASSWORD"))
                {
                    connectionString = CryptographHelper.RijndaelEncrypt(filter.ConnectionString, pass);
                }

                else if (upperConnection.Contains("SERVER") &&
                         upperConnection.Contains("DATABASE") &&
                         (upperConnection.Contains("TRUSTED_CONNECTION") ||
                          (upperConnection.Contains("USER ID") && upperConnection.Contains("PASSWORD"))))
                {
                    connectionString = CryptographHelper.RijndaelEncrypt(filter.ConnectionString, pass);
                }

                else if (upperConnection.Contains("DATA SOURCE") &&
                         upperConnection.Contains("PROVIDER"))
                {
                    connectionString = CryptographHelper.RijndaelEncrypt(filter.ConnectionString, pass);
                }
                else
                {
                    throw new ServiceException(CommonExceptionType.ValidationException,
                                               "ConnectionString parameter, must follow connection standards " + Environment.NewLine +
                                               "For Oracle" + Environment.NewLine +
                                               "DATA SOURCE=#########;PERSIST SECURITY INFO=FALSE;USER ID=######;PASSWORD=######;" + Environment.NewLine +
                                               "For SQL Server" + Environment.NewLine +
                                               "SERVER=###############;DATABASE=###############;[USER ID=######;PASSWORD=######;|TRUSTED_CONNECTION=TRUE;]" + Environment.NewLine +
                                               "For MS Access" + Environment.NewLine +
                                               "PROVIDER=###############;DATA SOURCE=###############;PERSIST SECURITY INFO=FALSE;[USER ID=######;PASSWORD=######;]");
                }
            }
            catch (Exception ex)
            {
                LogHelper.ExceptionAndThrow(ex);
            }

            return(connectionString);
        }
        public void EncryptAndDecryptDataUsingRSAKeys()
        {
            var publicKey  = "123";
            var privateKey = "123";

            var encriptedText = CryptographHelper.RsaEncrypt(_textToEncrypt, publicKey);
            var decriptedText = CryptographHelper.RsaDecrypt(encriptedText, privateKey);

            Assert.IsNotNull(encriptedText);
            Assert.IsNotNull(decriptedText);
            Assert.AreEqual(_textToEncrypt, decriptedText);
        }
        public void ValidateAndGetUserAuthorizationsOperation()
        {
            var auth = _ssoService.ValidateAndGetUserAuthorizations(new SsoAuthenticationDTO
            {
                EncriptedLogin      = CryptographHelper.RijndaelEncrypt("v-mussala", CommonConsts.CommonPassword),
                EncriptedPassword   = CryptographHelper.RijndaelEncrypt("Songoku&*78", CommonConsts.CommonPassword),
                EncriptedAppCode    = CryptographHelper.RijndaelEncrypt("SCB", CommonConsts.CommonPassword),
                LanguageCultureName = "EN-US"
            });

            Assert.IsNotNull(auth);
        }
Example #13
0
    public static void ExportLuaEx(string dirPath)
    {
        string tmpPath = Path.GetFullPath(Path.Combine(Application.dataPath, "tmp"));

        DirectoryDelete(tmpPath);
        CheckDirectory(tmpPath);

        string[]      include     = new string[] { ".lua", ".cs", ".txt", ".shader", ".py" };
        List <string> exportNames = new List <string>();

        string[] fileList = Directory.GetFiles(dirPath, "*.*", SearchOption.AllDirectories);
        for (int i = 0; i < fileList.Length; i++)
        {
            string fileName = fileList[i];
            string ext      = Path.GetExtension(fileName);
            if (Array.IndexOf <string>(include, ext) != -1)
            {
                string byteFileName = fileName.Replace(dirPath, "");
                if (byteFileName.StartsWith("\\"))
                {
                    byteFileName = byteFileName.Substring(1);
                }
                byteFileName  = byteFileName.Replace("\\", "%").Replace("/", "%").Replace(".", "%");
                byteFileName += ".bytes";
                exportNames.Add("Assets/tmp/" + byteFileName);
                File.Copy(Path.GetFullPath(fileName), Path.Combine(tmpPath, byteFileName), true);
            }
        }

        System.Threading.Thread.Sleep(1000);
        AssetDatabase.Refresh();

        ExportAssetBundle.BuildAssetBundles(exportNames.ToArray(), "Assets/tmp", "luaout.bytes", BuildAssetBundleOptions.DeterministicAssetBundle);

        string strOutputPath = Path.Combine(Application.streamingAssetsPath, PathUtil.Platform);

        CheckDirectory(strOutputPath);

        string luaoutPath = Path.Combine(Application.dataPath, "tmp/luaout.bytes");

        string luaExportPath = Path.GetFullPath(Path.Combine(strOutputPath, "lua_core.u3d"));

        byte[] by      = File.ReadAllBytes(luaoutPath);
        byte[] encrypt = CryptographHelper.Encrypt(by, key, iv);
        File.WriteAllBytes(luaExportPath, encrypt);

        DirectoryDelete(tmpPath);

        Debug.Log(luaExportPath + " export.");

        System.Threading.Thread.Sleep(100);
        AssetDatabase.Refresh();
    }
Example #14
0
 static public int constructor(IntPtr l)
 {
     try {
         CryptographHelper o;
         o = new CryptographHelper();
         pushValue(l, o);
         return(1);
     }
     catch (Exception e) {
         LuaDLL.luaL_error(l, e.ToString());
         return(0);
     }
 }
Example #15
0
 public static int constructor(IntPtr l)
 {
     try {
         CryptographHelper o;
         o=new CryptographHelper();
         pushValue(l,true);
         pushValue(l,o);
         return 2;
     }
     catch(Exception e) {
         return error(l,e);
     }
 }
Example #16
0
 public static int constructor(IntPtr l)
 {
     try {
         CryptographHelper o;
         o=new CryptographHelper();
         pushValue(l,o);
         return 1;
     }
     catch(Exception e) {
         LuaDLL.luaL_error(l, e.ToString());
         return 0;
     }
 }
Example #17
0
    /// <summary>
    /// 加载lua bundle
    /// </summary>
    /// <returns></returns>
    private IEnumerator loadLuaBundle(bool domain, LuaFunction onLoadedFn)
    {
        string keyName = "";
        string luaP    = CUtils.GetAssetFullPath("font.u3d");
        //Debug.Log("load lua bundle" + luaP);
        WWW luaLoader = new WWW(luaP);

        yield return(luaLoader);

        if (luaLoader.error == null)
        {
            byte[]      byts = CryptographHelper.Decrypt(luaLoader.bytes, DESHelper.instance.Key, DESHelper.instance.IV);
            AssetBundle item = AssetBundle.CreateFromMemoryImmediate(byts);

//            item = luaLoader.assetBundle;
#if UNITY_5
            TextAsset[] all = item.LoadAllAssets <TextAsset>();
            foreach (var ass in all)
            {
                keyName = Regex.Replace(ass.name, @"\.", "");
                //Debug.Log("cache : " + keyName);
                luacache[keyName] = ass;
            }
#else
            UnityEngine.Object[] all = item.LoadAll(typeof(TextAsset));
            foreach (var ass in all)
            {
                keyName = Regex.Replace(ass.name, @"\.", "");
                Debug.Log(keyName + " complete");
                luacache[keyName] = ass as TextAsset;
            }
#endif
            //Debug.Log("loaded lua bundle complete" + luaP);
//            luaLoader.assetBundle.Unload(false);
            item.Unload(false);
            luaLoader.Dispose();
        }

        DoUnity3dLua();
        if (domain)
        {
            DoMain();
        }

        if (onLoadedFn != null)
        {
            onLoadedFn.call();
        }
    }
Example #18
0
        public SsoAuthorizationDTO ValidateAndGetUserAuthorizations(SsoAuthenticationDTO sso)
        {
            var authorization = new SsoAuthorizationDTO {
                IsValid = false
            };

            try
            {
                if (string.IsNullOrEmpty(sso.EncriptedAppCode) ||
                    string.IsNullOrEmpty(sso.EncriptedLogin))
                {
                    throw new ServiceException(CommonExceptionType.ParameterException, "EncriptedAppCode and EncriptedLogin");
                }

                var appCode    = CryptographHelper.RijndaelDecrypt(sso.EncriptedAppCode, CommonConsts.CommonPassword);
                var login      = CryptographHelper.RijndaelDecrypt(sso.EncriptedLogin, CommonConsts.CommonPassword);
                var userFilter = new UserFilterDTO {
                    Login = login, LoadProfiles = true
                };

                //Get user data
                var worker = GetWorker(userFilter);

                //Validates user password if its a SSO user
                worker.ValidateUserCredential(sso.EncriptedPassword);

                //Get worker related apps filtered by AppCode
                worker.Applications = GetUserApplications(userFilter, new ApplicationFilterDTO
                {
                    ApplicationCode     = appCode,
                    LoadTranslations    = true,
                    LanguageCultureName = sso.LanguageCultureName
                });

                //Transforms user permissions to claims identity
                authorization.Claims  = worker.GetClaims();
                authorization.IsValid = (!worker.Validation.HasErrors && authorization.Claims.Count > 0);
            }
            catch (ServiceException ex)
            {
                //Suppress validations exceptions and returns an empty authorization
            }
            catch (Exception ex)
            {
                LogHelper.ExceptionAndThrow(ex);
            }

            return(authorization);
        }
Example #19
0
        /// <summary>
        /// 本地存储
        /// </summary>
        public static bool SaveLocalData(string fileName, string saveData)
        {
            string     fullPath = CUtils.PathCombine(CUtils.GetRealPersistentDataPath(), fileName);
            FileStream fs       = new FileStream(fullPath, FileMode.Create);

            if (fs != null)
            {
                byte[] bytes = CryptographHelper.Encrypt(Encoding.UTF8.GetBytes(saveData), key, iv);
                fs.Write(bytes, 0, bytes.Length);
                fs.Flush();
                fs.Close();
                return(true);
            }
            return(false);
        }
Example #20
0
    //[MenuItem("Custom/lua/解析lua", false, 1)]
    public static void LoadLua()
    {
        string saveFolderPath = EditorUtility.SaveFolderPanel("导出", null, "Assets");

        if (string.IsNullOrEmpty(saveFolderPath))
        {
            return;
        }
        Debug.Log(saveFolderPath);

        string strOutputPath = Path.Combine(Application.streamingAssetsPath, PathUtil.Platform);
        string luaExportPath = Path.GetFullPath(Path.Combine(strOutputPath, "lua_core.u3d"));

        byte[] bytes = File.ReadAllBytes(luaExportPath);

        byte[] byts = CryptographHelper.Decrypt(bytes, key, iv);

#if UNITY_5_3
        AssetBundle item = AssetBundle.LoadFromMemory(byts);
#else
        AssetBundle item = AssetBundle.LoadFromMemory(byts);
#endif

        string      keyName = "";
        TextAsset[] all     = item.LoadAllAssets <TextAsset>();
        foreach (TextAsset ass in all)
        {
            keyName = ass.name;
            string   absFilePath = keyName.Replace("%", "/");
            int      last        = absFilePath.LastIndexOf("/");
            string   cut0        = absFilePath.Substring(0, last);
            string   cut1        = absFilePath.Substring(last, absFilePath.Length - last).Replace("/", ".");
            string   newFilePath = cut0 + cut1;
            string   fullPath    = Path.Combine(saveFolderPath, newFilePath);
            FileInfo fi          = new FileInfo(fullPath);
            if (!fi.Directory.Exists)
            {
                fi.Directory.Create();
            }
            using (StreamWriter kWriter = new StreamWriter(fullPath, false, new System.Text.UTF8Encoding(false)))
            {
                kWriter.Write(ass.text);
                kWriter.Close();
            }
        }

        item.Unload(true);
    }
Example #21
0
 static public int CrypfString_s(IntPtr l)
 {
     try {
         System.String a1;
         checkType(l, 1, out a1);
         System.String a2;
         checkType(l, 2, out a2);
         var ret = CryptographHelper.CrypfString(a1, a2);
         pushValue(l, ret);
         return(1);
     }
     catch (Exception e) {
         LuaDLL.luaL_error(l, e.ToString());
         return(0);
     }
 }
    static int _CreateCryptographHelper(IntPtr L)
    {
        int count = LuaDLL.lua_gettop(L);

        if (count == 0)
        {
            CryptographHelper obj = new CryptographHelper();
            LuaScriptMgr.PushObject(L, obj);
            return 1;
        }
        else
        {
            LuaDLL.luaL_error(L, "invalid arguments to method: CryptographHelper.New");
        }

        return 0;
    }
        private static string GetConnectionString(Profile profile)
        {
            //Initializes and decrypts profile connection string
            string connectionString = CryptographHelper.RijndaelDecrypt(profile.ConnectionString, _password);

            //Mounts vault pattern to be attached in connection string
            if (profile.UsePattern)
            {
                var passwordPattern = CryptographHelper.RijndaelDecrypt(_pattern.PatternValue, _password).ToUpper();
                passwordPattern = _pattern.PatternOptions
                                  .Aggregate(passwordPattern, (pattern, option) =>
                                             pattern.Replace(option.Key, (string.IsNullOrWhiteSpace(option.Value) ? profile.Name : option.Value)));

                connectionString += passwordPattern;
            }

            return(connectionString);
        }
Example #24
0
 static public int Encrypt_s(IntPtr l)
 {
     try {
         System.Byte[] a1;
         checkType(l, 1, out a1);
         System.Byte[] a2;
         checkType(l, 2, out a2);
         System.Byte[] a3;
         checkType(l, 3, out a3);
         var ret = CryptographHelper.Encrypt(a1, a2, a3);
         pushValue(l, ret);
         return(1);
     }
     catch (Exception e) {
         LuaDLL.luaL_error(l, e.ToString());
         return(0);
     }
 }
Example #25
0
        /// <summary>
        /// 本地存储
        /// </summary>
        public static bool SaveLocalData(string fileName, string saveData)
        {
            string   fullPath = CUtils.PathCombine(CUtils.GetRealPersistentDataPath(), fileName);
            FileInfo fileInfo = new FileInfo(fullPath);

            if (!fileInfo.Directory.Exists)
            {
                fileInfo.Directory.Create();
            }
            // if (!fileInfo.Exists) fileInfo.Create();
            using (var sw = fileInfo.OpenWrite())
            {
                byte[] bytes = CryptographHelper.Encrypt(Encoding.UTF8.GetBytes(saveData), key, iv);
                sw.Write(bytes, 0, bytes.Length);
                sw.Flush();
            }

            return(true);
        }
Example #26
0
        /// <summary>
        /// lua bundle
        /// </summary>
        /// <returns></returns>
        private IEnumerator DecryptLuaBundle(string luaPath, bool isStreaming, LuaFunction onLoadedFn)
        {
            luaPath = CUtils.CheckWWWUrl(luaPath);
            Debug.Log("loadluabundle:" + luaPath);
            WWW luaLoader = new WWW(luaPath);

            yield return(luaLoader);

            if (luaLoader.error == null)
            {
                byte[] byts = CryptographHelper.Decrypt(luaLoader.bytes, DESHelper.instance.Key, DESHelper.instance.IV);
                AssetBundleCreateRequest abcreq = null;
#if UNITY_5_0 || UNITY_5_1 || UNITY_5_2
                abcreq = AssetBundle.CreateFromMemory(byts);
#else
                abcreq = AssetBundle.LoadFromMemoryAsync(byts);
#endif
                yield return(abcreq);

                var         item = abcreq.assetBundle;
                TextAsset[] all  = item.LoadAllAssets <TextAsset>();
                foreach (var ass in all)
                {
                    SetRequire(ass.name, ass);
                }

                item.Unload(false);
                luaLoader.Dispose();
            }
            else
            {
                Debug.LogWarning(luaLoader.error);
            }

            if (onLoadedFn != null)
            {
                onLoadedFn.call();
            }
            else
            {
                DoMain();
            }
        }
Example #27
0
        /// <summary>
        /// Validate database user password
        /// </summary>
        public void ValidateUserCredential(string password)
        {
            //Validates user password if it was provided
            if (UserExtraInfo.AccountTypeName == AccountType.SSOUser.ToString())
            {
                if (string.IsNullOrEmpty(password))
                {
                    Validation.Results.Add(new ValidationResult("Error: EncriptedPassword is null or empty"));
                }

                if (LoginExpirationDate.HasValue && LoginExpirationDate < DateTime.Now)
                {
                    Validation.Results.Add(new ValidationResult("Error: Login account expired"));
                }

                if (string.IsNullOrEmpty(WebSignature))
                {
                    Validation.Results.Add(new ValidationResult("Error: WebSignature is null or empty"));
                }

                if (!string.IsNullOrEmpty(password) &&
                    !string.IsNullOrEmpty(WebSignature))
                {
                    password = CryptographHelper.RijndaelDecrypt(password, CommonConsts.CommonPassword);

                    //Creates the password to decrypt PrivateKeys
                    var prefix = CommonResource.GetString("PassNumbers") + CommonResource.GetString("PassSpecialChars");
                    var pass   = prefix + CommonResource.GetString("PassText") + prefix;

                    var xmlPrivateKey         = CryptographHelper.RijndaelDecrypt(WebSignatureRsaKey.PrivateKey.GetDescription(), pass);
                    var clearTextWebSignature = CryptographHelper.RsaDecrypt(WebSignature, xmlPrivateKey);

                    if (password != clearTextWebSignature)
                    {
                        Validation.Results.Add(new ValidationResult("Error: Password mismatch."));
                    }
                }
            }
        }
Example #28
0
        /// <summary>
        /// Validates user using Windows or Forms authentication
        /// </summary>
        private bool ValidateUserCredentialAndGetClaims(LoginModel login)
        {
            //If its an signout action don´t get user data
            if (_ssoSigninSignout.RequestAction == SsoRequestParameter.WsSignOut.GetDescription())
            {
                return(true);
            }

            //Encripts user data and password for forms authentication
            if (!string.IsNullOrEmpty(login.Username) &&
                !string.IsNullOrEmpty(login.Password))
            {
                login.Username = CryptographHelper.RijndaelEncrypt(login.Username, CommonFrameworkResource.CommonFrameworkPassword.GetDescription());
                login.Password = CryptographHelper.RijndaelEncrypt(login.Password, CommonFrameworkResource.CommonFrameworkPassword.GetDescription());
            }

            var sso = new SsoAuthenticationDTO
            {
                EncriptedLogin      = login.Username,
                EncriptedPassword   = login.Password,
                LanguageCultureName = Thread.CurrentThread.CurrentCulture.Name.ToUpper(),
            };

            var userIdentity = ssoService.ValidateUserAndGetClaims(sso);
            var userIsValid  = (userIdentity != default(ClaimsIdentity) && userIdentity.IsAuthenticated);

            //Adds returned Claims Principal to SSO object
            if (userIsValid)
            {
                _ssoSigninSignout.ClaimsUser = new ClaimsPrincipal(new ClaimsIdentityCollection {
                    userIdentity
                });
            }

            return(userIsValid);
        }
Example #29
0
    //[MenuItem("Hugula/export lua [Assets\\Lua]", false, 12)]
    public static void exportLua()
    {
        checkLuaExportPath();

        string path = Application.dataPath + "/Lua";  //AssetDatabase.GetAssetPath(obj).Replace("Assets","");

        List <string> files = getAllChildFiles(path); // Directory.GetFiles(Application.dataPath + path);

        IList <string> childrens = new List <string>();

        foreach (string file in files)
        {
            if (file.EndsWith("lua"))
            {
                childrens.Add(file);
            }
        }
        Debug.Log("luajit path = " + luacPath);
        string crypName = "", fileName = "", outfilePath = "", arg = "";

        System.Text.StringBuilder sb = new System.Text.StringBuilder();

        DirectoryDelete(Application.dataPath + OutLuaPath);

        foreach (string filePath in childrens)
        {
            fileName = CUtils.GetURLFileName(filePath);
            //crypName=CryptographHelper.CrypfString(fileName);
            crypName    = filePath.Replace(path, "").Replace(".lua", "." + Common.LUA_LC_SUFFIX).Replace("\\", "/");
            outfilePath = Application.dataPath + OutLuaPath + crypName;
            checkLuaChildDirectory(outfilePath);

            sb.Append(fileName);
            sb.Append("=");
            sb.Append(crypName);
            sb.Append("\n");

#if Nlua || UNITY_IPHONE
            arg = "-o " + outfilePath + " " + filePath;
            File.Copy(filePath, outfilePath, true);
#else
            arg = "-b " + filePath + " " + outfilePath;             //for jit
            Debug.Log(arg);

            System.Diagnostics.Process.Start(luacPath, arg);//arg -b hello1.lua hello1.out
#endif
        }
        Debug.Log(sb.ToString());
        Debug.Log("lua:" + path + "files=" + files.Count + " completed");

        System.Threading.Thread.Sleep(1000);
        AssetDatabase.Refresh();

        //打包成assetbundle
        string luaOut = Application.dataPath + OutLuaPath;
        Debug.Log(luaOut);
        List <string>             luafiles       = getAllChildFiles(luaOut + "/", Common.LUA_LC_SUFFIX);
        string                    assetPath      = "Assets" + OutLuaPath;
        List <UnityEngine.Object> res            = new List <Object>();
        string                    relatePathName = "";
        foreach (string name in luafiles)
        {
            relatePathName = name.Replace(luaOut, "");
            string abPath = assetPath + relatePathName;
            Debug.Log(abPath);
            Debug.Log(relatePathName);
            Object txt = AssetDatabase.LoadAssetAtPath(abPath, typeof(TextAsset));
            txt.name = relatePathName.Replace(@"\", @".").Replace("/", "").Replace("." + Common.LUA_LC_SUFFIX, "");
            Debug.Log(txt.name);
            res.Add(txt);
        }

        string   cname   = "/luaout.bytes";
        string   outPath = luaOut;        //ExportAssetBundles.GetOutPath();
        string   tarName = outPath + cname;
        Object[] ress    = res.ToArray();
        Debug.Log(ress.Length);
        ExportAssetBundles.BuildAB(null, ress, tarName, BuildAssetBundleOptions.CompleteAssets);
//         Debug.Log(tarName + " export");
        AssetDatabase.Refresh();

        //Directory.CreateDirectory(luaOut);
        string realOutPath = ExportAssetBundles.GetOutPath() + "/font.u3d";
        byte[] by          = File.ReadAllBytes(tarName);
        Debug.Log(by);
        byte[] Encrypt = CryptographHelper.Encrypt(by, GetKey(), GetIV());

        File.WriteAllBytes(realOutPath, Encrypt);
        Debug.Log(realOutPath + " export");
    }
Example #30
0
        /// <summary>
        /// Gets the UD key.
        /// </summary>
        /// <returns>The UD key.</returns>
        /// <param name="url">url.</param>
        public static string GetUDKey(string url)
        {
            string udKey = CryptographHelper.CrypfString(url);

            return(udKey);
        }
    public static void exportLua()
    {
        checkLuaExportPath();

        string path = Application.dataPath + "/Lua/"; //AssetDatabase.GetAssetPath(obj).Replace("Assets","");

        List <string> files = getAllChildFiles(path); // Directory.GetFiles(Application.dataPath + path);

        IList <string> childrens = new List <string>();

        foreach (string file in files)
        {
            if (file.EndsWith("lua"))
            {
                childrens.Add(file);
            }
        }
        Debug.Log("luajit path = " + luacPath);
        string crypName = "", fileName = "", outfilePath = "", arg = "";

        System.Text.StringBuilder sb = new System.Text.StringBuilder();
        //refresh directory
        DirectoryDelete(Application.dataPath + OutLuaPath);
        CheckDirectory(Application.dataPath + OutLuaPath);
        //CheckDirectory(Application.dataPath.Replace("Assets","")+outPath);

        List <string> exportNames    = new List <string> ();

        foreach (string filePath in childrens)
        {
            fileName    = CUtils.GetURLFileName(filePath);
            crypName    = filePath.Replace(path, "").Replace(".lua", "." + Common.LUA_LC_SUFFIX).Replace("\\", "_").Replace("/", "_");
            outfilePath = Application.dataPath + OutLuaPath + crypName;
            exportNames.Add("Assets" + OutLuaPath + crypName);
            sb.Append(fileName);
            sb.Append("=");
            sb.Append(crypName);
            sb.Append("\n");

#if Nlua || UNITY_IPHONE
            arg = "-o " + outfilePath + " " + filePath; // luac
            File.Copy(filePath, outfilePath, true);     // source code copy
#else
            arg = "-b " + filePath + " " + outfilePath; //for jit
            //Debug.Log(arg);
            //System.Diagnostics.Process.Start(luacPath, arg);//jit
            File.Copy(filePath, outfilePath, true);// source code copy
#endif
        }
        Debug.Log("lua:" + path + "files=" + files.Count + " completed");
        System.Threading.Thread.Sleep(1000);
        AssetDatabase.Refresh();

        //u5 打包
        string outPath = ExportAssetBundles.GetOutPath();
        CheckDirectory(Application.dataPath.Replace("Assets", "") + outPath);
        ExportAssetBundles.BuildABs(exportNames.ToArray(), "Assets" + OutLuaPath, "luaout.bytes", BuildAssetBundleOptions.CompleteAssets);

        //Encrypt
        string tarName     = Application.dataPath + OutLuaPath + "luaout.bytes";
        string realOutPath = ExportAssetBundles.GetOutPath() + "/font.u3d";
        byte[] by          = File.ReadAllBytes(tarName);
        byte[] Encrypt     = CryptographHelper.Encrypt(by, GetKey(), GetIV());
        File.WriteAllBytes(realOutPath, Encrypt);
        Debug.Log(realOutPath + " export");
    }
Example #32
0
    public static void exportLua()
    {
        checkLuaExportPath();
        BuildScript.CheckstreamingAssetsPath();

        string info  = "luac";
        string title = "build lua";

        EditorUtility.DisplayProgressBar(title, info, 0);

        var childrens = AssetDatabase.GetAllAssetPaths().Where(p =>
                                                               (p.StartsWith("Assets/Lua") ||
                                                                p.StartsWith("Assets/Config")) &&
                                                               (p.EndsWith(".lua"))
                                                               ).ToArray();
        string path  = "Assets/Lua/";    //lua path
        string path1 = "Assets/Config/"; //config path
        string root  = Application.dataPath.Replace("Assets", "");

        Debug.Log("luajit path = " + luacPath);
        string crypName = "", fileName = "", outfilePath = "", arg = "";

        System.Text.StringBuilder sb = new System.Text.StringBuilder();
        //refresh directory
        DirectoryDelete(Application.dataPath + OutLuaPath);
        CheckDirectory(Application.dataPath + OutLuaPath);

        float allLen = childrens.Length;
        float i      = 0;

        List <string> exportNames = new List <string>();

        foreach (string file in childrens)
        {
            string filePath = Path.Combine(root, file);
            fileName    = CUtils.GetAssetName(filePath);
            crypName    = file.Replace(path, "").Replace(path1, "").Replace(".lua", "." + Common.LUA_LC_SUFFIX).Replace("\\", "_").Replace("/", "_");
            outfilePath = Application.dataPath + OutLuaPath + crypName;
            exportNames.Add("Assets" + OutLuaPath + crypName);
            sb.Append(fileName);
            sb.Append("=");
            sb.Append(crypName);
            sb.Append("\n");

#if Nlua || UNITY_IPHONE
            arg = "-o " + outfilePath + " " + filePath; // luac
            File.Copy(filePath, outfilePath, true);     // source code copy
#else
            arg = "-b " + filePath + " " + outfilePath; //for jit
            //Debug.Log(arg);
            //System.Diagnostics.Process.Start(luacPath, arg);//jit
            File.Copy(filePath, outfilePath, true);// source code copy
#endif
            i++;
            EditorUtility.DisplayProgressBar(title, info + "=>" + i.ToString() + "/" + allLen.ToString(), i / allLen);
        }
        Debug.Log("lua:" + path + "files=" + childrens.Length + " completed");
        System.Threading.Thread.Sleep(1000);
        AssetDatabase.Refresh();

        EditorUtility.DisplayProgressBar(title, "build lua", 0.99f);
        //u5 打包
        CheckDirectory(Path.Combine(Application.dataPath, OutLuaPath));
        BuildScript.BuildABs(exportNames.ToArray(), "Assets" + OutLuaPath, "luaout.bytes", BuildAssetBundleOptions.DeterministicAssetBundle);

        EditorUtility.DisplayProgressBar(title, "Encrypt lua", 0.99f);
        //Encrypt
        string tarName     = Application.dataPath + OutLuaPath + "luaout.bytes";
        string md5Name     = CUtils.GetRightFileName(Common.LUA_ASSETBUNDLE_FILENAME);
        string realOutPath = Path.Combine(BuildScript.GetOutPutPath(), md5Name);

        byte[] by      = File.ReadAllBytes(tarName);
        byte[] Encrypt = CryptographHelper.Encrypt(by, GetKey(), GetIV());
        File.WriteAllBytes(realOutPath, Encrypt);
        Debug.Log(realOutPath + " export");
        EditorUtility.ClearProgressBar();
    }
Example #33
0
    public static void ExportLua()
    {
        string path = Path.GetFullPath(Path.Combine(Application.dataPath, "Lua"));

        string tmpPath = Path.GetFullPath(Path.Combine(Application.dataPath, "tmp"));

        DirectoryDelete(tmpPath);
        CheckDirectory(tmpPath);

        List <string> sourceFiles = new List <string>();
        List <string> exportNames = new List <string>();

        List <string> files = getAllChildFiles(path, "lua");

        foreach (string filePath in files)
        {
            string file = Path.GetFullPath(filePath);
            if (!file.EndsWith(".lua"))
            {
                continue;
            }
            string byteFileName = file.Replace(path, "");
            if (byteFileName.StartsWith("\\") || byteFileName.StartsWith("/"))
            {
                byteFileName = byteFileName.Substring(1);
            }

            byteFileName = byteFileName.Replace(".lua", ".bytes").Replace("\\", "_").Replace("/", "_");
            exportNames.Add("Assets/tmp/" + byteFileName);
            //File.Copy(file, Path.Combine(tmpPath, byteFileName), true);
            string srcFile = file.Replace(Path.GetFullPath(Application.dataPath), "");
            srcFile = "Assets" + srcFile;
            Debug.Log(srcFile);
            sourceFiles.Add(srcFile);
        }
        //打包config
        string cfgPath = Path.GetFullPath(Path.Combine(Application.dataPath, "Config/config"));

        Debug.Log("Export Lua Path:" + cfgPath);
        List <string> cfgFiles = getAllChildFiles(cfgPath, "lua");

        foreach (string filePath in cfgFiles)
        {
            string file = Path.GetFullPath(filePath);
            if (!file.EndsWith(".lua"))
            {
                continue;
            }
            string byteFileName = file.Replace(cfgPath, "");
            if (byteFileName.StartsWith("\\") || byteFileName.StartsWith("/"))
            {
                byteFileName = byteFileName.Substring(1);
            }
            byteFileName = byteFileName.Replace(".lua", ".bytes").Replace("\\", "_").Replace("/", "_");
            byteFileName = "config_" + byteFileName;
            exportNames.Add("Assets/tmp/" + byteFileName);
            //File.Copy(file, Path.Combine(tmpPath, byteFileName), true);
            string srcFile = file.Replace(Path.GetFullPath(Application.dataPath), "");
            srcFile = "Assets" + srcFile;
            sourceFiles.Add(srcFile);
        }

        System.Threading.Thread.Sleep(1000);
        AssetDatabase.Refresh();

        JITBUILDTYPE jbt = GetLuaJitBuildType(EditorUserBuildSettings.activeBuildTarget);

        SLua.LuajitGen.compileLuaJit(sourceFiles.ToArray(), exportNames.ToArray(), jbt);

        System.Threading.Thread.Sleep(1000);
        AssetDatabase.Refresh();

        ExportAssetBundle.BuildAssetBundles(exportNames.ToArray(), "Assets/tmp", "luaout.bytes", optionsDefault);

        string strOutputPath = Path.Combine(Application.streamingAssetsPath, PathUtil.Platform);

        CheckDirectory(strOutputPath);

        string luaoutPath    = Path.Combine(Application.dataPath, "tmp/luaout.bytes");
        string luaExportPath = Path.GetFullPath(Path.Combine(strOutputPath, "lua.u3d"));

        byte[] by      = File.ReadAllBytes(luaoutPath);
        byte[] encrypt = CryptographHelper.Encrypt(by, KeyVData.Instance.KEY, KeyVData.Instance.IV);
        File.WriteAllBytes(luaExportPath, encrypt);

        DirectoryDelete(tmpPath);

        Debug.Log(luaExportPath + " export.");

        System.Threading.Thread.Sleep(100);
        AssetDatabase.Refresh();
    }