c# - PasswordDeriveBytes 8 and 24 raises ArgumentException in some orders - Stack Overflow

I'm using PasswordDeriveBytes in legacy code and can't use Rfc2898DeriveBytes just yet.When

I'm using PasswordDeriveBytes in legacy code and can't use Rfc2898DeriveBytes just yet.

When I'm getting 24 and then 8 bytes, everything works perfectly. But when I'm getting first 8 and then 24, it crashes with an ArgumentException. Very strange, because with a 32/16 combination it works in both orders.

var deriver1 = new PasswordDeriveBytes("mykey-123456789", []);
var key1 = deriver1.GetBytes(24);
var iv1 = deriver1.GetBytes(8);

var deriver2 = new PasswordDeriveBytes("mykey-123456789", []);
var iv2 = deriver2.GetBytes(8);
var key2 = deriver2.GetBytes(24);  // BOOM: ArgumentException: Offset and length were out of bounds...

I would not expect ArgumentException... or is this a bug of this deprecated class? Does anyone have an explanation to this or to whether I am doing something wrong?

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745158402a4614263.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信