【问题标题】:Specified key is not a valid size for this algorithm. Nothing else worked指定的密钥不是此算法的有效大小。没有其他工作
【发布时间】:2021-10-01 16:18:45
【问题描述】:

因此,在谷歌搜索了 2 个多小时后,我还没有真正找到解决此问题的任何有效解决方案。我正在尝试加密一个链接,但它每次都向我显示这个错误。

声明

                        if (F != null)
                        {
                            text = text.Replace("string license", "string license = @\"" + Convert.ToBase64String(F) + "\"");
                        }

加密

        {
            try
            {
                Aes aes = new AesManaged
                {
                    Key = new byte[] {},
                    IV = new byte[16],
                    Mode = CipherMode.CBC,
                    Padding = PaddingMode.Zeros
                };
                ICryptoTransform crypto;
                crypto = aes.CreateEncryptor();
                return crypto.TransformFinalBlock(message, 0, message.Length); //return encrypted value
            }
            catch (Exception x)
            {
                MessageBox.Show(x.Message);
                return null;
            }
        }

感谢您的回答。

【问题讨论】:

标签: c# string encryption base64


【解决方案1】:

我相信您的密钥需要 16 个字节长。 new byte[] {} 将创建一个 0 字节长的 Key

【讨论】:

    猜你喜欢
    • 2011-02-24
    • 2020-09-25
    • 1970-01-01
    • 2010-12-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-24
    相关资源
    最近更新 更多