指定的密钥不是此算法的有效大小 [英] Specified key is not a valid size for this algorithm

查看:27
本文介绍了指定的密钥不是此算法的有效大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个代码:

RijndaelManaged rijndaelCipher = new RijndaelManaged();

            // Set key and IV
            rijndaelCipher.Key = Convert.FromBase64String("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz012345678912");
            rijndaelCipher.IV = Convert.FromBase64String("1234567890123456789012345678901234567890123456789012345678901234");

我得到了:

Specified key is not a valid size for this algorithm.

Specified initialization vector (IV) does not match the block size for this algorithm.

这个字符串有什么问题?我可以数一下你的一些示例字符串吗?

What's wrong with this strings ? Can I count at some examples strings from You ?

推荐答案

当 base64 解码产生 48 字节(384 位)时,字符串ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz012345678912".RijndaelManaged 支持 128、192 和 256 位密钥.

The string "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz012345678912" when base64-decoded yields 48 bytes (384 bits). RijndaelManaged supports 128, 192 and 256 bit keys.

一个有效的 128 位密钥是 new byte[]{ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0xC, 0x0D, 0x0D } 或者如果您需要从 base64 获取它:Convert.FromBase64String("AAECAwQFBgcICQoLDA0ODw==").

A valid 128-bit key is new byte[]{ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F } or if you need to get it from base64 : Convert.FromBase64String("AAECAwQFBgcICQoLDA0ODw==").

默认块大小为 128 位,因此相同的字节数组将与 IV 相同.

The default blocksize is 128 bits, so the same byte-array will work as the IV.

这篇关于指定的密钥不是此算法的有效大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆