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

后端 未结 3 2111
礼貌的吻别
礼貌的吻别 2020-12-29 02:33

I am working on a base encryption method. I am using RijndaelManaged. I got this code from somewhere a long time ago, but can\'t remember where.

I had my code workin

3条回答
  •  长情又很酷
    2020-12-29 03:31

    You should be able to check how many bytes the IV needs to be using:

    algorithm.BlockSize / 8
    

    BlockSize is in bits, so 128 bits / 8 gives 16 bytes of ASCII, and you may also find Rfc2898DeriveBytes a useful class for producing keys.

    algorithm.IV = rfc2898DeriveBytesForIV.GetBytes(algorithm.BlockSize / 8);
    

    Hope it helps.

提交回复
热议问题