public static byte[] EncryptionOracle(out int randIndex) { var r = new Random(); randIndex = r.Next(0, Data.Length); var input = Data[randIndex]; return(AesCbc.Encrypt(Key, Iv, Convert.FromBase64String(input))); }
public static byte[] EncryptionOracle(string input) { var encoded = input.Replace(";", "%3B").Replace("=", "%3D"); var b1 = System.Text.Encoding.ASCII.GetBytes(Prefix); var b2 = System.Text.Encoding.ASCII.GetBytes(Suffix); var bytes = new List <byte>(); bytes.AddRange(b1); bytes.AddRange(System.Text.Encoding.ASCII.GetBytes(encoded)); bytes.AddRange(b2); return(AesCbc.Encrypt(Key, Iv, bytes.ToArray())); }
public static CipherMode EncryptEcbOrCbc(byte[] data, out CipherMode actualMode) { actualMode = Rand.Next(0, 2) == 0 ? CipherMode.ECB : CipherMode.CBC; var key = SecureRng.GenerateRandomBytes(KeySizeBytes); // Add prefix and suffix to data data = TransformData(data); byte[] encrypted; if (actualMode == CipherMode.ECB) { var padded = PaddingUtil.Pad(data, BlockSizeBytes); encrypted = AesEcb.Encrypt(key, padded); } else { var iv = SecureRng.GenerateRandomBytes(BlockSizeBytes); encrypted = AesCbc.Encrypt(key, iv, data); } var guessedMode = AesEcb.IsEcbEncrypted(encrypted, BlockSizeBytes) ? CipherMode.ECB : CipherMode.CBC; return(guessedMode); }