private void btnSave_Click(object sender, EventArgs e) { ConfigModel config = new ConfigModel(); config.Host = txtHost.Text; config.Port = Convert.ToInt32(txtPort.Text); config.Login = _crypto.Encrypt(txtLogin.Text); config.Password = _crypto.Encrypt(txtPassword.Text); config.Interval = Convert.ToInt32(txtInterval.Text); _config.Write(config); }
//--------------------------------- // Check if config file exists //--------------------------------- private void CreateDefaultConfig() { ConfigModel config = new ConfigModel(); config.Host = "192.168.1.1"; config.Port = 22; config.Login = aesCrypto.Encrypt("admin"); config.Password = aesCrypto.Encrypt("admin"); config.Interval = 2000; binaryConfig.Write(config); Log("Created default config file."); }
public static string EnAes(string data) { string appAesKey = "*7956$1lo0@#Zxp;"; string appAesIV = "@-8523769lQovg%&"; return(AesCrypto.Encrypt(data, appAesKey, appAesIV)); }
public static void TestObjectDisposed() { AesKey key = new AesKey(); AesIV iv = new AesIV(); AesCrypto crypto = new AesCrypto(key, iv, CipherMode.CBC, PaddingMode.None); crypto.Dispose(); Assert.Throws <ObjectDisposedException>(() => { crypto.Decrypt(new byte[16]); }); Assert.Throws <ObjectDisposedException>(() => { crypto.Encrypt(new byte[16]); }); Assert.Throws <ObjectDisposedException>(() => { crypto.CreateDecryptingTransform(); }); Assert.Throws <ObjectDisposedException>(() => { crypto.CreateEncryptingTransform(); }); }
public TideResponse AddFragment(AuthenticationModel model) { try { var usernameHash = model.Username.ConvertToUint64(); var result = _eos.CreateTransaction(new Transaction { Actions = new List <Action> { new Action { Account = _settings.Onboarding, Authorization = new List <PermissionLevel> { new PermissionLevel { Actor = _settings.Account, Permission = "active" } }, Name = "addfrag", Data = new { ork_node = _settings.Account, ork_url = model.SiteUrl, username = usernameHash, private_key_frag = AesCrypto.Encrypt(model.CvkPrivateFrag, _settings.Password), public_key = model.CvkPublic, pass_hash = AesCrypto.Encrypt(model.PasswordHash, _settings.Password), ork_public = _settings.PublicKey } } } }).Result; _logger.LogMsg("Added fragment for user", model); return(new TideResponse(true, null, null)); } catch (Exception e) { _logger.LogMsg("Failed adding fragment", model, e); return(new TideResponse(false, null, e.Message)); } }
public void TestEncrypt() { String encryptBody = AesCrypto.Encrypt(body, Key, Iv); Assert.IsTrue(encryptBody.Length > 0); Console.WriteLine(encryptBody); }
/// <summary> /// Initializes a new instance of the <see cref="Subkey"/> class. Different data is encrypted using /// different variants of the master encryption key. /// </summary> /// <param name="masterKey">The master key.</param> /// <param name="headerSubkey">The header subkey.</param> public Subkey(AesKey masterKey, HeaderSubkey headerSubkey) { if (masterKey == null) { throw new ArgumentNullException("masterKey"); } byte[] block = new byte[16]; byte subKeyValue; switch (headerSubkey) { case HeaderSubkey.Hmac: subKeyValue = 0; break; case HeaderSubkey.Validator: subKeyValue = 1; break; case HeaderSubkey.Headers: subKeyValue = 2; break; case HeaderSubkey.Data: subKeyValue = 3; break; default: throw new InternalErrorException("headerSubkey"); } block[0] = subKeyValue; using (AesCrypto aesCrypto = new AesCrypto(masterKey)) { _subKey = new AesKey(aesCrypto.Encrypt(block)); } }
private void btn_Encrypt_Click(object sender, EventArgs e) { String key = textBox_Key.Text.Trim(), iv = textBox_IV.Text.Trim(), body = textBox_Body.Text.Trim(); if (String.IsNullOrEmpty(key)) { MessageBox.Show("秘钥不能为空!", "温馨提示"); return; } if (String.IsNullOrEmpty(iv) && isIvEncrypt()) { MessageBox.Show("偏移量不能为空!", "温馨提示"); return; } if (String.IsNullOrEmpty(body)) { MessageBox.Show("待处理文本不能为空!", "温馨提示"); return; } var keyValue = KeyToBytes(); byte[] bytes = AesCrypto.Encrypt(Encoding.UTF8.GetBytes(body), keyValue.Key, keyValue.Value); DisplayCiphertexts(bytes); }
private async void Save_Click(object sender, RoutedEventArgs e) { try { var seed = seedTb.Text; var sfd = new SaveFileDialog(); var p = await sfd.ShowAsync(this); if (p != null && seed != null && seed != "") { var pw = new PasswordWindow(); var pass = await pw.ShowDialog <string>(this); string walletText = ""; if (pass != null) { walletText = AesCrypto.Encrypt(seed, pass); } else { walletText = seed; } File.WriteAllText(p, walletText); } } catch (Exception exception) { } }
public void TestEncryptNoIv() { var key = AesCrypto.CreateKey(); String encryptBody = AesCrypto.Encrypt(body, Encoding.UTF8.GetBytes(key)); Assert.IsTrue(encryptBody.Length > 0); Console.WriteLine(encryptBody); }
private void buttonAesEncrypt_Click(object sender, EventArgs e) { var crypto = new AesCrypto(this.textAesKey.Text, this.textAesIv.Text); this.textAesEncryptedOutput.Text = crypto.Encrypt(this.textAesPlaintext.Text); Clipboard.SetText(textAesEncryptedOutput.Text); }
public void Encryption_Test() { string testStr = Convert.ToBase64String(Encoding.ASCII.GetBytes("dev:test")); AesCrypto encryptor = new AesCrypto { KeyPhrase = "dev" }; Console.WriteLine(encryptor.Encrypt(testStr)); }
public void Should_Entrypt_Decrypt() { var person = "HassanHashemi"; var salt = Encoding.UTF8.GetBytes("*****@*****.**"); var aes = new AesCrypto(salt, "pass"); var encrypted = aes.Encrypt(person); var result = aes.Decrypt(encrypted); Assert.True(person == result); }
public void TestDecrypt() { String encryptBody = AesCrypto.Encrypt(body, Key, Iv); String decryptBody = AesCrypto.Decrypt(encryptBody, Key, Iv); Assert.IsNotNull(decryptBody); Assert.IsTrue(decryptBody.Length > 0); Console.WriteLine("密文:{0}", encryptBody); Console.WriteLine("明文:{0}", decryptBody); Assert.IsTrue(decryptBody.Equals(body)); }
public string Encrypt(string valueToEncrypt) { try { var encryptedValue = AesCrypto.Encrypt(valueToEncrypt); return(encryptedValue); } catch (Exception ex) { Logger.LogException(ex); throw Helper.CreateHttpResponseException(ex, "Error Encrypting Value"); } }
public void TestDecryptNoIv() { var key = AesCrypto.CreateKey(); String encryptBody = AesCrypto.Encrypt(body, Encoding.UTF8.GetBytes(key)); Console.WriteLine("密文:{0}", encryptBody); String decryptBody = AesCrypto.Decrypt(encryptBody, Encoding.UTF8.GetBytes(key)); Assert.IsNotNull(decryptBody); Assert.IsTrue(decryptBody.Length > 0); Console.WriteLine("明文:{0}", decryptBody); Assert.IsTrue(decryptBody.Equals(body)); }
public void Encrypt_should_encrypt_plainText() { var aesCrypto = new AesCrypto(); var key = Encoding.UTF8.GetBytes(Guid.NewGuid().ToString("N")); var encrypted = aesCrypto.Encrypt(_plainText, key); encrypted.Should().NotBeNullOrWhiteSpace(); encrypted.Should().NotBe(_plainText); var decrypted = aesCrypto.Decrypt(encrypted, key); decrypted.Should().NotBeNullOrWhiteSpace(); decrypted.Should().Be(_plainText); }
public static string EnCrypt(this string text) => AesCrypto.Encrypt(text);
private void Encrypt() { this.CustomVariable.Value = AesCrypto.Encrypt(this.CustomVariable.Value); this.CustomVariable.ValueIsEncrypted = true; this.NotifyPropertyChanged(() => this.ValueIsPlaintext); }
private void Encrypt() { ActiveDirectoryInfo.ActiveDirectoryAccountPassword = AesCrypto.Encrypt(ActiveDirectoryInfo.ActiveDirectoryAccountPassword); this.NotifyPropertyChanged(() => ActiveDirectoryInfo); }
public static void TestObjectDisposed() { AesKey key = new AesKey(); AesIV iv = new AesIV(); AesCrypto crypto = new AesCrypto(key, iv, CipherMode.CBC, PaddingMode.None); crypto.Dispose(); Assert.Throws<ObjectDisposedException>(() => { crypto.Decrypt(new byte[16]); }); Assert.Throws<ObjectDisposedException>(() => { crypto.Encrypt(new byte[16]); }); Assert.Throws<ObjectDisposedException>(() => { crypto.CreateDecryptingTransform(); }); Assert.Throws<ObjectDisposedException>(() => { crypto.CreateEncryptingTransform(); }); }
static void Main(string[] args) { if (args.Length < 2) { Console.WriteLine("Usage: ue.exe <grpc|http|sql|mongodb|dns|tcp|udp> <service-idenitifier> [dns-type]"); Console.WriteLine(" OR"); Console.WriteLine(" ue.exe <enc|dec> <string> [pepper]"); return; } try { Console.WriteLine("Service Domain = '{0}'", _generic.ServiceDomain); switch (args[0].ToLowerInvariant()) { case "enc": case "dec": var aes = new AesCrypto(); if (args.Length > 2) { aes.KeyPhrase = args[2]; } Console.WriteLine("Pepper = '{0}'", aes.KeyPhrase); if (args[0].ToLowerInvariant() == "enc") { Console.WriteLine("\nEncrypted = \"{aes:" + aes.Encrypt(args[1]) + "}\""); } else { string cipherText = args[1].Replace("{aes:", "").Replace("}", ""); Console.WriteLine("\nDecrypted = \"" + aes.Decrypt(cipherText) + "\""); } break; case "dns": if (Enum.TryParse(args[2], out DnsRecordType recordType)) { var query = new DnsQuery(args[1], recordType); DnsEntry[] records = query.Resolve().Result; foreach (DnsEntry rec in query.AllRecords) { Console.WriteLine($"({rec.Type}) {rec}"); } } break; case "grpc": var g = _grpc.Locate(args[1]).Result; foreach (GrpcEndpoint ep in g.Endpoints) { Console.WriteLine(ep.ToString()); } break; case "http": var w = _webapi.Locate(args[1]).Result; foreach (Uri u in w.Uris) { Console.WriteLine(u.ToString()); } break; case "sql": var sql = _database.Locate(args[1], DatabaseProtocol.Sql).Result; foreach (string sqlConnectionString in sql.ConnectionStrings) { Console.WriteLine(sqlConnectionString); } break; case "mongodb": var mongo = _database.Locate(args[1], DatabaseProtocol.MongoDb).Result; foreach (string mConnectionString in mongo.ConnectionStrings) { Console.WriteLine(mConnectionString); } break; case "tcp": var tcp = _generic.Locate(args[1], IpProtocol.TCP).Result; foreach (ServiceEndpoint ep in tcp.Endpoints) { Console.WriteLine(ep.ToString()); } break; case "udp": var udp = _generic.Locate(args[1], IpProtocol.UDP).Result; foreach (ServiceEndpoint ep in udp.Endpoints) { Console.WriteLine(ep.ToString()); } break; case "long-test": LongTest.RunTest(args[1]); break; } } catch (Exception ex) { BreakdownExcception(ex); } }