Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/285.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 以编程方式确定*.ts视频文件是否使用aes 128加密_C#_Testing_Encryption_Powershell_Aes - Fatal编程技术网

C# 以编程方式确定*.ts视频文件是否使用aes 128加密

C# 以编程方式确定*.ts视频文件是否使用aes 128加密,c#,testing,encryption,powershell,aes,C#,Testing,Encryption,Powershell,Aes,我想编写一个简单的自动测试,以确定是否使用AES 128加密对.ts视频文件进行了加密。我将有权访问加密和未加密的文件。我也可以拿到钥匙。我几乎可以访问所有内容,因为我正在与开发人员一起进行加密:) 我更愿意做一个更高级的测试,而不仅仅是检查文件大小是否不同 我能写一些简单的测试代码吗?我会用c#或powershell编写代码 我绝对没有这方面的经验,所以请把我当孩子看待 谢谢这背后的真正原因是什么?所以你不会对一个文件加密两次,或者解密两次?如果我们了解需求,也许有更好的解决方案 但是,根据我

我想编写一个简单的自动测试,以确定是否使用AES 128加密对.ts视频文件进行了加密。我将有权访问加密和未加密的文件。我也可以拿到钥匙。我几乎可以访问所有内容,因为我正在与开发人员一起进行加密:)

我更愿意做一个更高级的测试,而不仅仅是检查文件大小是否不同

我能写一些简单的测试代码吗?我会用c#或powershell编写代码

我绝对没有这方面的经验,所以请把我当孩子看待


谢谢

这背后的真正原因是什么?所以你不会对一个文件加密两次,或者解密两次?如果我们了解需求,也许有更好的解决方案

但是,根据我目前看到的情况,似乎您必须尝试解密该文件,如果失败,则假定该文件未加密……但这可能非常耗时。我不确定是否有其他方法,除了打开文件进行读取,读取一行,看看是否有明文,假设您知道要将其与什么明文进行比较


如果您试图测试加密/解密是否正常工作,则可以获取包含已知明文的输入文件,使用正确的密钥对其进行加密,然后解密两次—一次使用正确的密钥,第二次使用无效密钥。比较三种方法的结果

如果TS容器是完全加密的,那么查看文件是否是有效的MPEG-TS文件可能会更有效,而不是试图确定它是否加密。如果它是无效的,假设它是加密的。您可以读取文件的前几个字节来验证格式。此处记录了格式(或“幻数”):

希望这能有所帮助。

我最终制作了一个c#命令行

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication2
{
    using System.IO;
    using System.Security.Cryptography;

    class Program
    {
        static void Main(string[] args)
        {

            if (args.Length == 0)
            {
                Console.WriteLine("<key> <iv> <encryptedfile> <outputdecryptedfile>");
                Environment.Exit(-1);
            }

            //Console.ReadLine();
            byte[] encryptionKey = StringToByteArray(args[0]);
            byte[] encryptionIV = StringToByteArray(args[1]);

            try
            {
                using (FileStream outputFileStream = new FileStream(args[3], FileMode.CreateNew))
                {
                    using (FileStream inputFileStream = new FileStream(args[2], FileMode.Open))
                    {
                        using (var aes = new AesManaged { Key = encryptionKey, IV = encryptionIV, Mode = CipherMode.CBC })
                        using (var encryptor = aes.CreateDecryptor())
                       using (var cryptoStream = new CryptoStream(inputFileStream, encryptor, CryptoStreamMode.Read))
                        {
                            cryptoStream.CopyTo(outputFileStream);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }            
        }

        public static byte[] StringToByteArray(string hex)
        {
            return Enumerable.Range(0, hex.Length)
                             .Where(x => x % 2 == 0)
                             .Select(x => Convert.ToByte(hex.Substring(x, 2), 16))
                             .ToArray();
        }

    }
}
使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用系统文本;
命名空间控制台应用程序2
{
使用System.IO;
使用System.Security.Cryptography;
班级计划
{
静态void Main(字符串[]参数)
{
如果(args.Length==0)
{
控制台。写线(“”);
环境。退出(-1);
}
//Console.ReadLine();
字节[]encryptionKey=StringToByteArray(args[0]);
字节[]encryptionIV=StringToByteArray(args[1]);
尝试
{
使用(FileStream outputFileStream=newfilestream(args[3],FileMode.CreateNew))
{
使用(FileStream inputFileStream=newfilestream(args[2],FileMode.Open))
{
使用(var aes=new AesManaged{Key=encryptionKey,IV=encryptionIV,Mode=CipherMode.CBC})
使用(var encryptor=aes.CreateDecryptor())
使用(var cryptoStream=new cryptoStream(inputFileStream,encryptor,CryptoStreamMode.Read))
{
CopyTo(outputFileStream);
}
}
}
}
捕获(例外情况除外)
{
Console.WriteLine(例如ToString());
}            
}
公共静态字节[]StringToByteArray(字符串十六进制)
{
返回可枚举的范围(0,十六进制长度)
。其中(x=>x%2==0)
.Select(x=>Convert.ToByte(十六进制子字符串(x,2,16))
.ToArray();
}
}
}

我在一家拥有版权视频的媒体公司工作。我们需要测试以确保加密发生。这是一个有趣的想法,尝试用错误的密钥解密,然后用正确的密钥解密,看看是否会得到不同的结果:)是否有一个简单的命令可以使用powershell中的密钥解密文件?@user952342不是一个简单的命令,不,但它不是/太/坏;搜索“powershell加密aes”,您可以找到一些示例,在本页底部的MSDN上--有一个powershell示例--它也使用aes。