C#-未处理加密异常

C#-未处理加密异常,c#,cryptography,C#,Cryptography,我对下面的代码已经有几天的问题了,我真的不知道为什么我对它有这么多的问题,希望有人能给我指出正确的方向,也许我想得太多了 An unhandled exception of type 'System.Security.Cryptography.CryptographicException' occurred in mscorlib.dll 附加信息:错误数据 这是密码 return Encoding.ASCII.GetString(new TripleDESCryptoServiceProvi

我对下面的代码已经有几天的问题了,我真的不知道为什么我对它有这么多的问题,希望有人能给我指出正确的方向,也许我想得太多了

An unhandled exception of type 'System.Security.Cryptography.CryptographicException' occurred in mscorlib.dll
附加信息:错误数据

这是密码

return Encoding.ASCII.GetString(new TripleDESCryptoServiceProvider() { Key = new MD5CryptoServiceProvider().ComputeHash(Encoding.ASCII.GetBytes(key)), Mode = CipherMode.ECB, Padding = PaddingMode.PKCS7 }.CreateDecryptor().TransformFinalBlock(encrypted.Split('-').Select(s => Convert.ToByte(s, 16)).ToArray(), 0, encrypted.Split('-').Select(s => Convert.ToByte(s, 16)).ToArray().Length));
这就是所谓的

{
        if (args.Length == 0)
            return;

        if (args[0] == "new")
            File.Delete("old_updater.exe");
        else if (args[0] != Encryption.Decrypt_Param("06-8A-AB-DD-64-4C-6D-ED-AD-83-4A-1E-80-E4-36-15", "Incompitis Ingoramous"))
            Process.GetCurrentProcess().Kill();

        if (Process.GetProcessesByName("Updater").Length > 1)
            Process.GetCurrentProcess().Kill();

        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);
        Application.Run(new MainForm());
    }

分解代码有帮助

您得到的错误在TransformFinalBlock中。示例代码中的加密数据似乎没有填充


将填充更改为
PaddingMode。无
,它将不再抛出错误。

如果不尝试使其成为一行,加密就足够难了。请在发布前清理代码,并测试中间值。我强烈建议你做得不够,而不是做得过火。