AES Gingerbread

我怕爱的太早我们不能终老 提交于 2019-12-01 00:24:54

The answer is that you shouldn't really be doing what you are doing at all. Here is the culprit:

sr.setSeed(seed);
kgen.init(128, sr); // 192 and 256 bits may not be available
SecretKey skey = kgen.generateKey();

You should never pad your key with some un-predictable random value because you will need to recreate this same exact key later on. Here are some key lines from the android docs

"Seeding SecureRandom may be insecure"

Although it is common practice to seed Random with the current time, that is dangerous with SecureRandom since that value is predictable to an attacker and not appropriate for secure use.

Anyway, I know your argument will be that you are just "padding" the key and the security of what you are doing is not a big deal.

If you are going to accept keys of 128 bits for 192 or 256 bit implementations, then you must implement a repeatable method of expanding the key to 192 or 256 bits. You can even add all 0's to the key if you wanted to, but the key really is that it must be done in some way that you can repeat it on every system.

In any case, you may also want to consider that what you are doing may be used on systems other than Android. In those cases, using a more "portable" method to expand a key should be chosen.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!