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




If you're getting  exception when trying to assigned key to a symmetric key and getting error message below :-

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

And your code probably look like something below :-


Then you need to go into debug mode and start looking into the supported size for IV as shown in diagram below :-

As you can see, IV is 16 bytes, so you need to provide 16 bytes. The same goes for Key field too, if you're adding anything to it.


As long as you provide a valid key size, then we're good and you're code will be ready.





Comments

Anonymous said…
i m getting the same error if i used hard coded way it work fine but when i try to use the value from appsetting and written in the model class string AesKey256 = new ConfigurationBuilder().AddJsonFile("appsettings.json").Build().GetSection("Ikey")["AesKey256"]; like this i got the error that vector value more than block size i tried lot but none help me

Popular posts from this blog