//读取lua字节码(非Editor使用) public byte[] LoadLuaByteCode(string luaName) { byte[] bytes = null; //读取Data FileStream fs = new FileStream(PathUtility.StoragePath + "/Script/Data" + ScriptManager.Instance.GetJitFileSuffix(), FileMode.OpenOrCreate); BinaryReader br = new BinaryReader(fs); LuaFileFormat fdata = bytecodeData.luaList[luaName]; fs.Seek((long)bytecodeData.fileStarIndex + fdata.pos, SeekOrigin.Begin); bytes = br.ReadBytes(fdata.len); if (luaName.Contains("protocal/") || luaName.Contains("conf/")) { bytes = EncryptUtility.DecryptByte(bytes); } br.Close(); fs.Close(); if (bytes != null) { fileCache[luaName] = bytes; } else { throw new Exception("LoadLuabytecode Error! Bytes Is Null!"); } return(bytes); }
static void EncryptAndCopyFile(string excelName, ExcelDirType dirType) { string name = excelName.ToLower(); string bundleName = ExcelConfig.GetBundleName(dirType, name); string src = Path.Combine(Path.Combine(Application.dataPath, _buildOutputPath), bundleName); string dest = Path.Combine(Path.Combine(Application.dataPath, _streamingPath), bundleName); if (File.Exists(src)) { byte[] originalBytes = File.ReadAllBytes(src); byte[] encryptedBytes = null; if (AssetConfig.IsExcelAssetBundleEncrypted) { encryptedBytes = EncryptUtility.AES_Encrypt(originalBytes); } else { encryptedBytes = originalBytes; } File.WriteAllBytes(dest, encryptedBytes); } else { //Debug.LogError("EncryptAndCopyFile fail: file doesn't exist: " + src); } }
public void GivenAnOriginalText_WhenEncrypt_ResultShouldBeValidAndDecryptable(string originalText) { var cipherText = EncryptUtility.EncryptTextToBase64WithAes(originalText, Key); var plainText = EncryptUtility.DecryptTextFromBase64WithAes(cipherText, Key); Assert.Equal(originalText, plainText); }
public ProcessResult Process(ElementNode node, ProcessContext context = null, Dictionary <string, object> settings = null) { var processResult = new ProcessResult(); if (string.IsNullOrEmpty(node?.Value?.ToString())) { return(processResult); } var input = node.Value.ToString(); try { node.Value = EncryptUtility.DecryptTextFromHexStringWithAes(input, _key); } catch (Exception exc) { _logger.LogWarning(exc, "Decryption failed. Returning original value."); } _logger.LogDebug($"Fhir value '{input}' at '{node.Location}' is decrypted to '{node.Value}'."); return(processResult); }
public void GivenAnEncryptRule_WhenProcess_NodeShouldBeEncrypted() { AnonymizationFhirPathRule[] rules = new AnonymizationFhirPathRule[] { new AnonymizationFhirPathRule("Patient.address", "address", "Patient", "encrypt", AnonymizerRuleType.FhirPathRule, "Patient.address"), }; AnonymizationVisitor visitor = new AnonymizationVisitor(rules, CreateTestProcessors()); var patient = CreateTestPatient(); var patientNode = ElementNode.FromElement(patient.ToTypedElement()); patientNode.Accept(visitor); patientNode.RemoveEmptyNodes(); var patientCity = patientNode.Select("Patient.address[0].city").FirstOrDefault(); var key = Encoding.UTF8.GetBytes("1234567890123456"); var plainValue = EncryptUtility.DecryptTextFromBase64WithAes(patientCity.Value.ToString(), key); Assert.Equal("patienttestcity1", plainValue); patient = patientNode.ToPoco <Patient>(); Assert.Single(patient.Meta.Security); Assert.Contains(SecurityLabels.MASKED.Code, patient.Meta.Security.Select(s => s.Code)); }
public bool AddStudent(StudentModel sModel) { //TODO if user exist not insert StudentLogic studentLogicBL = new StudentLogic(); StudentsDetail studentsDetailList = new StudentsDetail(); studentsDetailList.UserName = sModel.UserName; //Encrypt Password var keyNew = EncryptUtility.GeneratePassword(10); var encryptPassword = EncryptUtility.EncodePassword(sModel.Password, keyNew); studentsDetailList.Password = encryptPassword; studentsDetailList.student_first_name = sModel.FirstName; studentsDetailList.student_last_name = sModel.LastName; studentsDetailList.student_middle_name = sModel.MiddleName; studentsDetailList.student_address1 = sModel.Address_Line1; studentsDetailList.student_city = sModel.City; studentsDetailList.student_country = sModel.Country; studentsDetailList.student_email = sModel.Email; studentsDetailList.student_graduation_year = sModel.GraduationYear; studentsDetailList.student_id = sModel.StudentId; studentsDetailList.is_international_student = sModel.isInternationStudent; studentsDetailList.date_created = DateTime.Now; return(studentLogicBL.AddStudent(studentsDetailList)); //return false; }
public ActionResult EncryptUtility(EncryptUtility model) { try { if (!string.IsNullOrEmpty(model.EncryptString)) { model.ValueDecript = model.EncryptString.Trim().Decrypt(); } else { model.ValueDecript = string.Empty; } if (!string.IsNullOrEmpty(model.DecryptString)) { model.ValueEncript = model.DecryptString.Trim().Encrypt(); } else { model.ValueEncript = string.Empty; } } catch (Exception ex) { ViewBag.isError = "Error"; ViewBag.Error = ex.Message; } return(View(model)); }
//初始化 存储字节码读取位置和长度 public void InitLuaBytecode() { FileStream fs = new FileStream(PathUtility.StoragePath + "/Script/Data" + ScriptManager.Instance.GetJitFileSuffix(), FileMode.OpenOrCreate); BinaryReader br = new BinaryReader(fs); byte[] fileData = br.ReadBytes((int)fs.Length); string fileString = System.Text.Encoding.UTF8.GetString(fileData); br.Close(); fs.Close(); int index1 = fileString.IndexOf("[xList]:"); int index2 = fileString.IndexOf("[info]:"); string temp = fileString.Substring(index1 + 8, index2 - index1 - 9); temp = EncryptUtility.DecryptStr(temp); //解密 string[] arr = temp.Split('-'); bytecodeData.luaList = new Dictionary <string, LuaFileFormat>(); for (int i = 0, len = arr.Length; i < len; ++i) { string[] d = arr[i].Split('|'); LuaFileFormat fdata = new LuaFileFormat(d[0], Convert.ToInt32(d[1]), Convert.ToInt32(d[2])); bytecodeData.luaList[d[0]] = fdata; } bytecodeData.fileStarIndex = index2 + 7; LogUtility.Log("InitLuaBytecode success!"); }
public ActionResult Update(string encryptId) { OrderFullViewModel model = new OrderFullViewModel(); int id = !string.IsNullOrEmpty(encryptId) ? EncryptUtility.DecryptId(encryptId) : 0; //List<EnumInfo> listOrderType = GetEnumValuesAndDescriptions<OrderTypeEnum>(); //List<EnumInfo> listSourceType = GetEnumValuesAndDescriptions<SourceTypeEnum>(); List <OrderDetailViewModel> listOrderDetail = new List <OrderDetailViewModel>(); int totalRow = 0; List <Product> listProduct = (List <Product>)_productBo.GetList("", out totalRow); if (listProduct != null && listProduct.Count > 0) { foreach (Product product in listProduct) { OrderDetailViewModel orderDetailViewModel = new OrderDetailViewModel(product); listOrderDetail.Add(orderDetailViewModel); } } if (id > 0) { model = _orderBo.GetByFullValueById(id); model.lstOrderDetailViewModel = listOrderDetail; model.ListProductViewModel = _orderBo.GetByOrderId(id).ToList(); model.ListDistrict = (List <District>)_districtBoCached.GetAll(); model.ListWard = (List <Ward>)_wardBoCached.GetByDistrictId(model.DistrictId); if (model.DeliverDate == DateTime.MinValue) { model.DeliverDate = DateTime.Now; } else { } model.DeliverDateStr = model.DeliverDate.ToString("dd/MM/yyyy HH:mm"); ViewBag.Title = "Sửa đơn hàng"; } else { var result = new Order(); List <District> listDistrict = (List <District>)_districtBoCached.GetAll(); List <Ward> listWard = new List <Ward>(); model = new DVG.WIS.PublicModel.OrderFullViewModel(result, new District(), new Ward(), listOrderDetail); model.ListDistrict = listDistrict; //model.ListOrderType = listOrderType; model.DeliverDate = DateTime.Now; model.DeliverDateStr = DateTime.Now.ToString("dd/MM/yyyy HH:mm"); model.ListProductViewModel = new List <OrderDetailViewModel>(); model.OrderType = -1; model.SourceType = -1; ViewBag.Title = "Tạo đơn hàng"; } model.ProductViewModelItem = new OrderDetailViewModel(); model.CityCode = "SG"; return(View(model)); }
/// <summary> /// 创建连接工厂 /// </summary> /// <returns></returns> private static ConnectionFactory CrateFactory() { ConnectionFactory factory = new ConnectionFactory(); factory.HostName = Config.MqConfig.HostName; factory.UserName = Config.MqConfig.UserName; factory.Password = EncryptUtility.DesDecrypt(Config.MqConfig.PassWord); factory.Port = Config.MqConfig.Port; return(factory); }
public static string Encrypt(this string src, EncryptType encryptType = EncryptType.Normal) {//编码后 if (encryptType == EncryptType.Normal) { return(EncryptUtility.Encode("" + src).EnCode()); //.Replace("=","-equl-").Replace("/", "-sprit-").Replace("+", "-add-"); } else { return(EncryptUtility.Md5Encrypt("" + src)); } }
private IEnumerator AssetBundleLoadAsync() { while (true) { if (AssetBundleAsyncLoadQueue.Count > 0) { CurrentLoader = AssetBundleAsyncLoadQueue.Dequeue(); CurrentLoaderName = CurrentLoader.AssetBundleName; if (CurrentLoader.LoadState == enLoadState.None) { } else { CurrentLoader.LoadState = enLoadState.Loading; AssetBundleCreateRequest assetBundleCreateRequest = null; if (CurrentLoader.LoadMethod == enResourceLoadMethod.LoadFromFile) { assetBundleCreateRequest = AssetBundle.LoadFromFileAsync(CurrentLoader.AssetBundleName); } else if (CurrentLoader.LoadMethod == enResourceLoadMethod.LoadFromMemory) { assetBundleCreateRequest = AssetBundle.LoadFromMemoryAsync( FileUtility.ReadAllBytes(CurrentLoader.AssetBundleName)); } else if (CurrentLoader.LoadMethod == enResourceLoadMethod.LoadFromMemoryDecrypt) { assetBundleCreateRequest = AssetBundle.LoadFromMemoryAsync( EncryptUtility.AssetBundleDecrypt( FileUtility.ReadAllBytes(CurrentLoader.AssetBundleName))); } else if (CurrentLoader.LoadMethod == enResourceLoadMethod.LoadFromStream) { assetBundleCreateRequest = AssetBundle.LoadFromStreamAsync(FileUtility.Open(CurrentLoader.AssetBundleName)); } yield return(assetBundleCreateRequest); if (CurrentLoaderName == CurrentLoader.AssetBundleName && CurrentLoader.LoadState != enLoadState.None) { if (assetBundleCreateRequest != null) { CurrentLoader?.OnSelfAssetBundleLoadComplete(assetBundleCreateRequest.assetBundle); } } } CurrentLoader = null; } else { yield return(null); } } }
public void TestMethod1() { var tripleStr = EncryptUtility.EncryptByTriple("password"); TestContext.WriteLine("EncryptByTriple=" + EncryptUtility.EncryptByTriple("password")); TestContext.WriteLine("EncryptByTriple=" + EncryptUtility.DecryptByTriple(tripleStr)); var md5 = EncryptUtility.EncryptByMD5("password"); TestContext.WriteLine("EncryptByMD5=" + EncryptUtility.EncryptByMD5("password")); var comStr = EncryptUtility.EncryptByTriple("password", "加密字符串"); TestContext.WriteLine("EncryptByTriple=" + comStr); }
private string ProcessStringConnection() { var connectionString = Configuration.GetConnectionString("equitaliadb"); if (string.IsNullOrEmpty(connectionString)) { connectionString = Environment.GetEnvironmentVariable(StringConnectionEV, EnvironmentVariableTarget.Machine); connectionString = EncryptUtility.Decrypt(connectionString); } else { Environment.SetEnvironmentVariable(StringConnectionEV, EncryptUtility.Encrypt(connectionString), EnvironmentVariableTarget.Machine); } return(connectionString); }
public ProcessResult Process(ElementNode node, ProcessContext context = null, Dictionary <string, object> settings = null) { var processResult = new ProcessResult(); if (string.IsNullOrEmpty(node?.Value?.ToString())) { return(processResult); } var input = node.Value.ToString(); node.Value = EncryptUtility.EncryptTextToBase64WithAes(input, _key); _logger.LogDebug($"Fhir value '{input}' at '{node.Location}' is encrypted to '{node.Value}'."); processResult.AddProcessRecord(AnonymizationOperations.Encrypt, node); return(processResult); }
public OrderOnListModel(Entities.Order order) { OrderId = order.order_id; EncryptId = EncryptUtility.EncryptId(order.order_id.ToString()); Code = order.code; OrderCode = order.order_code; CustomerName = order.customer_name; DistrictId = order.district_id; DeliveryAddress = order.delivery_address; CustomerPhone = order.customer_phone; CustomerNote = order.customer_note; CreatedBy = order.created_by; ModifiedBy = order.modified_by; ReasonNote = order.reason_note; Status = order.status; StatusStr = Utils.GetEnumDescription((OrderStatusEnum)order.status); DeliveryStatus = order.delivery_status; RequestType = order.request_type; DeliveryStatusStr = Utils.GetEnumDescription((DeliveryStatus)order.delivery_status); RequestTypeStr = Utils.GetEnumDescription((RequestTypeEnum)order.request_type); CreatedDateStr = order.created_date.ToString("dd/MM/yyyy HH:mm:ss"); ModifiedDateStr = order.modified_date.ToString("dd/MM/yyyy HH:mm:ss"); if (order.delivery_date != DateTime.MinValue) { DeliveryDateStr = order.delivery_date.Value.ToString("dd/MM/yyyy HH:mm"); } else { DeliveryDateStr = "Giao ngay"; } PriceStr = StringUtils.ConvertNumberToCurrency(order.price); OriginPriceStr = StringUtils.ConvertNumberToCurrency(order.origin_price); ShipFeeStr = StringUtils.ConvertNumberToCurrency(order.ship_fee); SourceTypeStr = Utils.GetEnumDescription((SourceTypeEnum)order.source_type); OrderTypeStr = Utils.GetEnumDescription((OrderTypeEnum)order.order_type); OrderType = order.order_type; }
private string DecryptText(string text) { return(EncryptUtility.DecryptTextFromBase64WithAes(text, Encoding.UTF8.GetBytes(TestEncryptKey))); }
public void GivenAnEncryptedBase64Text_WhenDecrypt_OriginalTextShouldBeReturned(string cipherText, string originalText) { var plainText = EncryptUtility.DecryptTextFromBase64WithAes(cipherText, Key); Assert.Equal(originalText, plainText); }
public void GivenAInvalidBase64Text_WhenDecrypt_ExceptionShouldBeThrown(string cipherText) { Assert.Throws <FormatException>(() => EncryptUtility.DecryptTextFromBase64WithAes(cipherText, Key)); }
public static string Decrypt(this string src, EncryptType encryptType = EncryptType.Normal) { //解码前 return(EncryptUtility.Decode(src.DeCode())); //.Replace("-equl-", "=").Replace("-sprit-", "/").Replace("-add-", "+")); }