public void EncryptResultTest() { var str = "helloworld"; var key = "MTIzNDU2Nzg4NzY1NDMyMQ=="; //1234567887654321 var iv = "MTIzNDU2Nzg5MGFiY2RlZg=="; //1234567890abcdef var aesEncryptor = new AesEncryptor(key, iv); var encrypted = aesEncryptor.Encrypt(str); Assert.Equal("5vpVXOvT+drFQQSH3KXi6Q==", encrypted); var keyBytes = Convert.FromBase64String(key); var ivBytes = Convert.FromBase64String(iv); var aesEncryptor2 = new AesEncryptor(keyBytes, ivBytes); var encrypted2 = aesEncryptor2.Encrypt(str); Assert.Equal(encrypted, encrypted2); Assert.Equal("5vpVXOvT+drFQQSH3KXi6Q==", encrypted2); }
public async Task <IActionResult> Update([DataSourceRequest] DataSourceRequest request, WebPluginConstantViewModel viewModel) { var tenantId = viewModel.TenantId; if (!isSysAdmin) { tenantId = db.CurrentTenantId; } var model = db.WebPluginConstants.First(n => n.TenantId == tenantId && n.WebPluginConstantId == viewModel.WebPluginConstantId); if (ModelState.IsValid) { await this.TryUpdateModelAsync <WebPluginConstantViewModel, WebPluginConstant>(model, "", m => { return(m.ElementType == null); }); if (model.Value.StartsWith("encrypt:")) { if (tenantId == null || !options.Value.UseExplicitTenantPasswords) { model.Value = PasswordSecurity.Encrypt(model.Value.Substring(8)); } else { var t = db.Tenants.First(n => n.TenantId == tenantId); if (!string.IsNullOrEmpty(t.TenantPassword)) { var pwd = Convert.FromBase64String(t.TenantPassword); model.Value = AesEncryptor.Encrypt(model.Value.Substring(8), pwd, false); } else { model.Value = PasswordSecurity.Encrypt(model.Value.Substring(8)); } } } model.TenantId = tenantId; await db.SaveChangesAsync(); } return(Json(await new[] { model.ToViewModel <WebPluginConstant, WebPluginConstantViewModel>() }.ToDataSourceResultAsync(request, ModelState))); }
void Awake() { //saveFilePath = Path.Combine(Application.persistentDataPath,"saveFile.json"); saveFilePath = Path.Combine(Application.persistentDataPath, filename); saveFile = new SaveFile(); encryptor = new AesEncryptor(); if (!File.Exists(saveFilePath)) { saveFile.saveVersion = 1.00f; saveFile.creationDate = Convert.ToString(DateTime.Now); saveFile.saveDate = Convert.ToString(DateTime.Now); // File.WriteAllText(saveFilePath, saveFile.GetJson()); byte[] encryptedSaveFile = encryptor.Encrypt(saveFile.GetJson(), JSON_ENCRYPTED_KEY, JSON_ENCRYPTED_IV); File.WriteAllBytes(saveFilePath, encryptedSaveFile); } else { Load(); } }
//private bool CheckLDevice(string devName) //{ // string LDate = CheckLDate(); // Encryptor en = new AesEncryptor(); // if (LInfo != null) // { // } // return true; //} private void UpdateAppset() { Encryptor en = new AesEncryptor(); using (RegistryKey skey = Registry.LocalMachine.OpenSubKey("Software", true)) { using (RegistryKey key = skey.CreateSubKey("IdentaMaster", RegistryKeyPermissionCheck.ReadWriteSubTree)) { byte[] entropy = { 0x00, 0x01, 0x02, 0x01, 0x00, 0x04, 0xBB, 0x17, 0x8b, 0xf6, 0xa2, 0x15, 0xe2, 0x64, 0x11, 0x9a }; appSet[0] = DateTime.Now.ToString(); string newappset = appSet[0]; foreach (var set in appSet) { if (newappset != set) { newappset += "..." + set; } } foreach (var devctrl in pluginManager.DeviceControls) { if (!appSet.Contains(devctrl.ToString())) { appSet.Add(devctrl.ToString()); newappset += "..." + devctrl.ToString(); } } newappset += "^^^"; //newappset = newappset.Replace("\\0", ""); var encappset = System.Text.Encoding.Default.GetBytes(newappset);// System.Text.Encoding.UTF8.GetString(); byte[] toenc = new byte[(16 - encappset.Length % 16) + encappset.Length]; encappset.CopyTo(toenc, 0); byte[] encAppSet = en.Encrypt(toenc, entropy); key.SetValue("AppSet", encAppSet); } } }
public void SetUp() { var subject = new AesEncryptor("SOME_KEY"); _result = subject.Encrypt("PASSWORD"); }
public string Convert(string value) { return(encryptor.Encrypt(value)); }
public string HashPassword(ApplicationUser user, string password) { return(AesEncryptor.Encrypt(password)); }