public AuthManager() { instance = null; sendAES = new AESCryption(SEND_IV, SEND_KEY); saveAES = new AESCryption(SAVE_IV, SAVE_KEY); accessToken = null; }
void Start() { if (!File.Exists(FileName)) { return; } // 読込 string config = File.ReadAllText(FileName); config = AESCryption.Decrypt(config); string[] token = config.Split(','); Access = new AccessTokenResponse { Token = token[0], TokenSecret = token[1], UserId = token[2], ScreenName = token[3] }; // 認証済 Text.text = Ready; Input.placeholder.GetComponent <Text>().text = PlaceholderReady; }
/// <summary> /// 转换Token /// </summary> /// <param name="loginUser"></param> /// <returns></returns> public static string ToToken(LoginUser loginUser) { var tokenTemplate = JsonConvert.SerializeObject(loginUser); var token = AESCryption.EncryptText(tokenTemplate, AESCryption.Salt); return(token); }
/// <summary> /// 转换LoginUser /// </summary> /// <param name="token"></param> /// <returns></returns> public static LoginUser ParseLoginUser(string token) { var jsonTemplate = AESCryption.DecryptText(token, AESCryption.Salt); var loginUser = JsonConvert.DeserializeObject <LoginUser>(jsonTemplate); loginUser.Token = token; return(loginUser); }
private async Task CreateOrModifyEmployee(EmployeeRequestDto employeeRequestDto) { if (employeeRequestDto.OperationStatus == OperationModel.Create) { employeeRequestDto.Salt = Utils.Number(8); employeeRequestDto.Password = AESCryption.EncryptText(employeeRequestDto.Password, employeeRequestDto.Salt); await _employeeAppService.CreateAsync(employeeRequestDto); } else if (employeeRequestDto.OperationStatus == OperationModel.Modify) { await _employeeAppService.ModifyAsync(employeeRequestDto); } }
/// <summary> /// Encrypt the message with password /// </summary> /// <param name="secruedMsg">the message to be encrypted</param> /// <param name="password">the password to encrypt or decrypt the above message, salt will generate based on this value</param> /// <returns></returns> public static byte[] EncryptAESSecruedMsg(string secruedMsg, string password, byte[] saltBytes) { byte[] encryptedMsg = null; validUserInputs(secruedMsg, password, getStringFromBytes(saltBytes)); try { encryptedMsg = AESCryption.AES_Encrypt(getBytesFromString(secruedMsg), getBytesFromString(password), saltBytes); } catch (Exception) { encryptedMsg = null; } return(encryptedMsg); }
public UserService() { sendAES = new AESCryption(SEND_IV, SEND_KEY); saveAES = new AESCryption(SAVE_IV, SAVE_KEY); if (emailDictionary == null) { emailDictionary = new Dictionary <string, string>(); } if (userIdDictionary == null) { userIdDictionary = new Dictionary <string, string>(); } }
public static string DecryptAESSecruedMsg(byte[] encryptedMsg, string password, byte[] saltBytes) { string decryptedMsg = null; validUserInputs(getStringFromBytes(encryptedMsg), password, getStringFromBytes(saltBytes)); try { byte[] decryptMsg = AESCryption.AES_Decrypt(encryptedMsg, getBytesFromString(password), saltBytes); decryptedMsg = getStringFromBytes(decryptMsg); } catch (Exception) { decryptedMsg = null; } return(decryptedMsg); }
// AssetBundleの復号化 private static AssetBundle DecryptingAssetBundle(AssetBundle bundle) { TextAsset textAsset = bundle.LoadAsset <TextAsset>(bundle.name); // nullチェック if (textAsset == null) { Debug.Log("[" + bundle.name + "]" + " inner asset is Null."); return(bundle); } bundle.Unload(false); byte[] decrypt = AESCryption.Decryption(textAsset.bytes); AssetBundle decryptBundle = AssetBundle.LoadFromMemory(decrypt); Debug.Log("[" + decryptBundle.name + "]" + " is decryped."); return(decryptBundle); }
void OnAccessTokenCallback(bool success, Twitter.AccessTokenResponse response) { if (success) { // 認証 Access = response; Text.text = Ready; Input.placeholder.GetComponent <Text>().text = PlaceholderReady; Input.text = ""; // 保存 string config = ""; config += Access.Token + ","; config += Access.TokenSecret + ","; config += Access.UserId + ","; config += Access.ScreenName + ","; config = AESCryption.Encrypt(config); File.WriteAllText(FileName, config); } }
/// <summary> /// 用户登录 /// </summary> /// <param name="input"></param> /// <returns></returns> public async Task <LoginUser> Login(EmployeeRequestDto input) { var userAccount = await _employeeAppService.EmployeeLogin(input.UserId); if (userAccount == null) { var _loginUser = new LoginUser() { IsSucceed = false, Message = "用户名不存在!" }; return(await Task.FromResult(_loginUser)); } var encryptPassword = AESCryption.EncryptText(input.Password, userAccount.Salt); if (!string.Equals(encryptPassword, userAccount.Password)) { var _loginUser = new LoginUser() { IsSucceed = false, Message = "密码错误!" }; return(await Task.FromResult(_loginUser)); } //var menuIds = await GetEmployeeMenuAsync(userAccount.Id); var elements = await GetEmployeeModuleElementAsync(userAccount.Id); var elementIds = elements.Select(e => e.Id).ToList(); var elementDtos = await _moduleElementAppService.GetElementByIds(elementIds); var routePaths = elementDtos.Select(r => r.RoutePath).ToList(); return(await Task.FromResult(new LoginUser() { RoutePaths = routePaths, IsSucceed = true, Name = userAccount.Name, Account = userAccount.UserId, ExpireDateTime = DateTime.Now.AddHours(8), UserId = userAccount.Id, })); }
static void Decryption() { // 保存先のパス設定 string outputPath = "AESCryption/Dencrypt"; if (!Directory.Exists(outputPath)) { Directory.CreateDirectory(outputPath); } // エディタ上で選択されたオブジェクトを取得 Object[] objs = Selection.objects; // 復号化ファイルの保存 foreach (Object obj in objs) { TextAsset t = (TextAsset)obj; byte[] data = AESCryption.Decryption(t.bytes); string path = outputPath + "/" + t.name + ".bytes"; File.WriteAllBytes(path, data); } Debug.Log("[AESCryption]: Decryption completed."); }
/// <summery> /// 暗号化AssetBundle生成 /// </summery> public static void BuildAssetBundlesForAES(BuildAssetBundleOptions buildOptions = BuildAssetBundleOptions.None) { // Resourcesから暗号化キーを取得 AESConfig config = Resources.Load <AESConfig>("AESConfig"); // ------------ // 暗号化情報が正しいか確認 if (config == null) { Debug.LogError("Dosen't find \"AESConfig.asset\"."); return; } else if (string.IsNullOrEmpty(config.Password) || string.IsNullOrEmpty(config.Salt)) { Debug.LogError("Please set AES Password and Salt. AES configuration menu is [AssetBundles/Open AES Config]"); return; } else if (config.Salt.Length < 8) { Debug.LogError("AES Salt is must over 8 chars."); return; } // ------------ // 一時ディレクトリ作成 string dirName = "____CryptingABs"; string tmpPath = "Assets/" + dirName; if (!Directory.Exists(tmpPath)) { // 作成 Directory.CreateDirectory(tmpPath); } // フォルダの中身が存在していた場合は削除 else if (Directory.GetFileSystemEntries(tmpPath).Length > 0) { DeleteTemporaryFiles(tmpPath, true); } // AssetBundleBuild 1回目 BuildPipeline.BuildAssetBundles(tmpPath, buildOptions, EditorUserBuildSettings.activeBuildTarget); // ------------ // 書き出されたAssetBundleに暗号化を施す処理 // 保存したファイル一覧を取得 string[] files = Directory.GetFiles(tmpPath); // AssetBundleのリネーム処理 foreach (string str in files) { // AssetBundle本体に.bytes拡張子を付与しつつ、不要ファイルを削除 if (!(str.Contains(".manifest") || str.Contains(".meta"))) { // ディレクトリ名と同じファイル (____CryptingABs) だった場合は削除 string[] s = str.Split('/'); if (s[s.Length - 1] == dirName) { File.Delete(str); } else { File.Move(str, str + ".bytes"); // リネーム } } else { File.Delete(str); // 削除 } } // 再度、AssetBundle全ファイルのパスを取得 files = Directory.GetFiles(tmpPath); // ------------ // 書き出されたAssetBundleを暗号化して、再度暗号化済みAssetBundleを書き出す処理 AssetBundleBuild[] buildMap = new AssetBundleBuild[files.Length]; // 暗号化処理実行 for (int i = 0; i < files.Length; i++) { string file = files[i]; // 暗号化符号作成 string[] s = file.Split('/'); string cryptoSign = Path.Combine(tmpPath, AssetBundleManager.CRYPTO_SIGN + s[s.Length - 1]); StreamWriter sign = File.CreateText(cryptoSign); sign.Close(); byte[] plain = File.ReadAllBytes(file); // byteデータ取得 byte[] encData = AESCryption.Encryption(plain); // 暗号化 File.WriteAllBytes(file, encData); // 暗号化済みAssetBundleを書き出す // BuildMap設定 string[] str = file.Split(new Char[] { '/', '.' }); string name = str[str.Length - 2]; Debug.Log("BuildTargetAsset : " + name); buildMap[i].assetBundleName = name; buildMap[i].assetNames = new string[] { file, cryptoSign }; } // 一度プロジェクトをリセットして、暗号化したAssetBundleを反映させる AssetDatabase.Refresh(); // 暗号化済みAssetBundle保存パス string absOutputPath = Path.Combine(kAssetBundlesOutputPath, BaseLoader.GetPlatformFolderForAssetBundles(EditorUserBuildSettings.activeBuildTarget)); if (!Directory.Exists(absOutputPath)) { Directory.CreateDirectory(absOutputPath); } // AssetBundleBuild 2回目 BuildPipeline.BuildAssetBundles(absOutputPath, buildMap, buildOptions, EditorUserBuildSettings.activeBuildTarget); // 一時ファイルの削除 DeleteTemporaryFiles(tmpPath); // 完了 AssetDatabase.Refresh(); Debug.Log("Successful creation of encrypted AssetBundles."); }