database 如何在oracle中使用DBMS_CRYPTO.encrypt函数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/32472691/
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
How to use DBMS_CRYPTO.encrypt function in oracle
提问by ITQuest
I want to encrypt password column in the database and I am trying to use encrypt function present inside DBMS_CRYPTO
package (have given execute access from sys account to the current user) but I am getting the following error.
Please give me some examples of how to use this function:
我想加密数据库中的密码列,并且我正在尝试使用DBMS_CRYPTO
包中存在的加密函数(已将 sys 帐户的执行访问权限授予当前用户),但出现以下错误。请举例说明如何使用此功能:
select DBMS_CRYPTO.encrypt('12345', dbms_crypto.DES_CBC_PKCS5, 'A1') from dual;
Error:
错误:
ORA-06553: PLS-221: 'DES_CBC_PKCS5' is not a procedure or is undefined 06553. 00000 - "PLS-%s: %s"
ORA-06553: PLS-221: 'DES_CBC_PKCS5' 不是过程或未定义 06553. 00000 - "PLS-%s: %s"
采纳答案by Marmite Bomber
The constant dbms_crypto.DES_CBC_PKCS5 is referenceble on PL/SQL only - not from SQL.
常量 dbms_crypto.DES_CBC_PKCS5 仅可在 PL/SQL 上引用 - 而不是来自 SQL。
You must replace it with literal value in the SELECT statement.
您必须在 SELECT 语句中用文字值替换它。
To get the value use PL/SQL block
要获取值,请使用 PL/SQL 块
begin
dbms_output.put_line(dbms_crypto.DES_CBC_PKCS5);
end;
/
.
.
4353
You must also use a longer key
您还必须使用更长的密钥
select DBMS_CRYPTO.encrypt(UTL_RAW.CAST_TO_RAW ('ABCDEFGH12345'), 4353 /* = dbms_crypto.DES_CBC_PKCS5 */, 'A1A2A3A4A5A6CAFE') from dual;
9320CBCBD25E8721BD04990A0EAEAF00
回答by Plaute
The answer above is fine, I add just some information about 4353. I saw this request used as is and I noticed this value is not really understood.
上面的答案很好,我只添加了一些关于 4353 的信息。我看到这个请求按原样使用,我注意到这个值没有被真正理解。
4353 is an additionof three informations about encryption used(des, aes and so on), block cipher mode of operation(ecb or cbc) and padding mode.
4353 是关于使用的加密(des、aes 等)、分组密码操作模式(ecb 或 cbc)和填充模式的三个信息的添加。
So, 4353stands for 1 (des) + cbc mode (256) + pkcs5 padding (4096)
所以,4353代表 1 (des) + cbc 模式 (256) + pkcs5 padding (4096)
If you prefer aes 256, you have to use 4356
如果您更喜欢aes 256,则必须使用4356
4358stands for aes 128
4358代表aes 128
and so on.
等等。
The Oracle page which describes the different parameters is here.
描述不同参数的 Oracle 页面在这里。
Hope this additional information helps everyone understand better DBMS_CRYPTO.
希望这些附加信息可以帮助大家更好地理解DBMS_CRYPTO。
回答by Calebe Santos
Encrypt
加密
select DBMS_CRYPTO.encrypt(UTL_RAW.CAST_TO_RAW('ABCDEFGH12345'), 4353 /* = dbms_crypto.DES_CBC_PKCS5 */, UTL_RAW.CAST_TO_RAW ('A1A2A3A4A5A6CAFE')) from dual;
Decrypt
解密
select UTL_RAW.CAST_TO_varchar2(DBMS_CRYPTO.decrypt('80AA4DEA59B77C433A2142AE9CDD235A', 4353, UTL_RAW.CAST_TO_RAW ('A1A2A3A4A5A6CAFE'))) from dual;