mcrypt_encrypt():大小的键 [英] mcrypt_encrypt(): Key of size

查看:216
本文介绍了mcrypt_encrypt():大小的键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

mcrypt_encrypt():此算法不支持的大小为10的密钥。只支持尺寸为16,24或32的键!

mcrypt_encrypt(): Key of size 10 not supported by this algorithm. Only keys of sizes 16, 24 or 32 supported!

http://i.stack.imgur.com/qE1ZD.png

我如何解决这个问题?

推荐答案

过去,如果你的密钥太短,PHP将用\0来填补它。从5.6版本开始就不一样了。您应该检查所使用的密码所需的密钥数量是多少: http:// php。 net / manual / en / function.mcrypt-get-key-size.php 请注意,还有其他检查密钥大小的方法,请检查文档。简单的方式我了解密钥大小:ASCII中的'fubar'字符串是5 * 8 = 40字节(每个字符8个字节)。但这是对使用中的字符集的假设。 php.net中的一些注释更好地解释了如何滚动正确大小的密钥:

Used to be if your key was too short that PHP would pad it with \0. This is no longer the case since PHP version 5.6.0. You should check how big required key is for the cipher being used: http://php.net/manual/en/function.mcrypt-get-key-size.php Note there are other ways to check key size, check the documentation. Simple way I understand key size: a string like 'fubar' in ASCII is 5 * 8 = 40 bytes (8 bytes per char). But that's making assumptions about character set in use. Some comments at php.net better explain how to roll a key of correct size:

$ key = pack('H *',bcb04b7e103a0cd8b54763051cef08bc55abe029fdebae5e1d417e2ffb2a00a3);

$key = pack('H*', "bcb04b7e103a0cd8b54763051cef08bc55abe029fdebae5e1d417e2ffb2a00a3");

这里64字符串将被转换为32字节的键,因为bc是一个字节,b0是另一个等等。从 http://php.net/manual/en/function.mcrypt-encrypt.php

Here the 64 char string will be converted into 32 byte key because bc is a byte, b0 is another, etc. From http://php.net/manual/en/function.mcrypt-encrypt.php

您可以使用strlen()仔细检查字节数。从上面的例子strlen($ key)将打印出32。

You can double check number of bytes with strlen(). From above example strlen($key) will print out 32.

这篇关于mcrypt_encrypt():大小的键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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