vb.net 调用本机函数“aes_decrypt”时参数计数不正确
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27804238/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Incorrect parameter count in the call to native function 'aes_decrypt'
提问by Bryan
I am trying to move our encryption from Code to the database to speed things up. When I attempt to decrypt the information using this select statement I get an incorrect parameter count error.
我正在尝试将我们的加密从代码移动到数据库以加快速度。当我尝试使用此 select 语句解密信息时,我收到一个不正确的参数计数错误。
SELECT AES_DECRYPT(u.strFirstName,'usa2010') FROM EncryptingTest.tblUser u;
I've looked at the documentation and this should work. Can someone tell me what I am doing wrong??
我查看了文档,这应该可行。有人可以告诉我我做错了什么吗??
EDIT I have tried Restarting the MySQL Server to no avail. The server Version is 5.6.22
编辑我试过重新启动 MySQL 服务器无济于事。服务器版本为 5.6.22
采纳答案by ???ěxě?
From the example you provided it seems ok. Can you see about casting it first?
从您提供的示例来看,它似乎没问题。你能先看看铸造它吗?
SELECT CAST(AES_DECRYPT(u.strFirstName,'usa2010') AS CHAR(50)) FROM EncryptingTest.tblUser u;
Please check this link it has some great resources on the issue your facing...
请检查此链接它有一些关于您面临的问题的很好的资源...
http://mysqlblog.fivefarmers.com/2014/03/27/mysql-5-6-17-now-with-better-encryption/
http://mysqlblog.fivefarmers.com/2014/03/27/mysql-5-6-17-now-with-better-encryption/
EDIT- The actual fix
编辑- 实际修复
Using AES_ENCRYPT() or AES_DECRYPT() with block_encryption_mode set to a block cipher other than ECB will produce an error if the IV is not provided:
如果未提供 IV,则使用 AES_ENCRYPT() 或 AES_DECRYPT() 并将 block_encryption_mode 设置为 ECB 以外的分组密码将产生错误:
mysql> SET @@session.block_encryption_mode = 'aes-256-cbc';
Query OK, 0 rows affected (0.00 sec)
查询正常,0 行受影响(0.00 秒)
mysql> SELECT HEX(AES_ENCRYPT('test', 'key'));
ERROR 1582 (42000): Incorrect parameter count in the call to native function 'aes_encrypt' mysql> SELECT HEX(AES_ENCRYPT('test', 'key', RANDOM_BYTES(16))); +---------------------------------------------------+ | HEX(AES_ENCRYPT('test', 'key', RANDOM_BYTES(16))) | +---------------------------------------------------+ | 2EFBA8708925C1DF8B661E57938FAE5E | +---------------------------------------------------+ 1 row in set (0.00 sec) Note that the IV isn't itself stored in the resulting encrypted output – it's an artifact that you'll have to track separately to get the decrypted values back:
错误 1582 (42000):调用本机函数 'aes_encrypt' mysql> SELECT HEX(AES_ENCRYPT('test', 'key', RANDOM_BYTES(16))) 时参数计数不正确;+------------------------------------------------- --+ | HEX(AES_ENCRYPT('test', 'key', RANDOM_BYTES(16))) | +------------------------------------------------- --+ | 2EFBA8708925C1DF8B661E57938FAE5E | +------------------------------------------------- --+ 集合中的 1 行(0.00 秒)请注意,IV 本身并不存储在生成的加密输出中——它是一个工件,您必须单独跟踪才能取回解密值:
mysql> SET @iv = RANDOM_BYTES(16);
Query OK, 0 rows affected (0.01 sec)
查询正常,0 行受影响(0.01 秒)
mysql> SELECT HEX(AES_ENCRYPT('test', 'key', @iv));
+--------------------------------------+ | HEX(AES_ENCRYPT('test', 'key', @iv)) | +--------------------------------------+ | 650CE9E699ECA922E09E80CEBE51BFC7 | +--------------------------------------+ 1 row in set (0.00 sec)
+--------------------------------------+ | HEX(AES_ENCRYPT('test', 'key', @iv)) | +--------------------------------------+ | 650CE9E699ECA922E09E80CEBE51BFC7 | +--------------------------------------+ 1 行(0.00 秒)
mysql> SELECT AES_DECRYPT(UNHEX('650CE9E699ECA922E09E80CEBE51BFC7'), 'key', @iv);
+--------------------------------------------------------------------+
+------------------------------------------------- -------------------+
AES_DECRYPT(UNHEX('650CE9E699ECA922E09E80CEBE51BFC7'), 'key', @iv) |
+--------------------------------------------------------------------+ | test | +--------------------------------------------------------------------+ 1 row in set (0.00 sec)
+------------------------------------------------- -------------------+ | 测试 | +------------------------------------------------- -------------------+ 1 行(0.00 秒)

