// Генерировать ключ private void btn_generate_key_Click(object sender, EventArgs e) { if (AlgName == "AES") { aescng.GenerateKey(); this.txt_key.Text = alg.ByteArrayTOStringHEX(aescng.Key); } if (AlgName == "3DES") { tripledes.GenerateKey(); this.txt_key.Text = alg.ByteArrayTOStringHEX(tripledes.Key); } }
public void AesCngCreateEncryptor() { using var aes = new AesCng(); using var rng = new RNGCryptoServiceProvider(); var noParams = aes.CreateEncryptor(); // Compliant aes.GenerateKey(); var withGeneratedKey = aes.CreateEncryptor(); // Compliant var constantIV = new byte[16]; var withConstant = aes.CreateEncryptor(aes.Key, constantIV); // Noncompliant aes.GenerateIV(); aes.CreateEncryptor(); var withGeneratedKeyAndIV = aes.CreateEncryptor(aes.Key, aes.IV); aes.CreateDecryptor(aes.Key, constantIV); // Compliant, we do not check CreateDecryptor rng.GetBytes(constantIV); var fromRng = aes.CreateEncryptor(aes.Key, constantIV); }