Oracle:如何调用重载过程?

发布于 2024-11-04 22:54:47 字数 408 浏览 0 评论 0原文

如何正确调用DBMS_OBFUSCATION_TOOLKIT.DESEncrypt? (如果可能,不使用 PL/SQL)

select DBMS_OBFUSCATION_TOOLKIT.DESEncrypt('x','y') from dual;

不起作用,因为 DESEncrypt 已重载:

ORA-06553: PLS-307: Too many declarations of "DESENCRYPT" match this call
06553. 00000 -  "PLS-%s: %s"
*Cause:    
*Action:

有没有办法选择 DESENCRYPT 的一种实现(可能是 VARCHAR2 变体)来避免此错误?

How to properly call DBMS_OBFUSCATION_TOOLKIT.DESEncrypt? (without using PL/SQL if possible)

select DBMS_OBFUSCATION_TOOLKIT.DESEncrypt('x','y') from dual;

doesn't work because DESEncrypt is overloaded:

ORA-06553: PLS-307: Too many declarations of "DESENCRYPT" match this call
06553. 00000 -  "PLS-%s: %s"
*Cause:    
*Action:

Is there a way to choose one implementation of DESENCRYPT (possibly the VARCHAR2 variant) to avoid this error?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

无悔心 2024-11-11 22:54:47

在 Oracle 11G 中,您可以使用这样的命名表示法:

select DBMS_OBFUSCATION_TOOLKIT.DESEncrypt(input_string=>'x',key_string=>'y')
from dual;

我认为在早期版本的 Oracle 中不可能明确地调用这些函数,除非创建一个包装函数并调用它。

In Oracle 11G you can use named notation like this:

select DBMS_OBFUSCATION_TOOLKIT.DESEncrypt(input_string=>'x',key_string=>'y')
from dual;

I don't think it is possible to call these functions unambiguously in earlier versions of Oracle, except by creating a wrapper function and calling that instead.

筱果果 2024-11-11 22:54:47

在这里,只需通过提供参数名称让它知道要使用哪个重载即可!

select DBMS_OBFUSCATION_TOOLKIT.DesEncrypt(INPUT_STRING=>'11112abc',KEY_STRING=>'4578ccde') 
from dual ;

回报

M5��w5Z

注意,你的密钥至少需要8个字节:

ORA-28234: 密钥长度太短
ORA-06512: 在
“SYS.DBMS_OBFUSCATION_TOOLKIT_FFI”,
ORA-06512: 第 21 行
“SYS.DBMS_OBFUSCATION_TOOLKIT”,行
126
28234. 00000 - “密钥长度太短”
*原因:指定的密钥对于算法来说太短。 DES
需要至少 8 个字节的密钥。三重 DES 需要
两键模式至少 16 字节,三键模式至少 24 字节
模式。
*操作:指定更长的密钥。


您可以总是尝试使用包装函数(正如托尼建议的那样)

create or replace
function DesEncrypt(pinputString IN VARCHAR2 , pKeyString in VARCHAR2) RETURN varchar2
IS
BEGIN
return DBMS_OBFUSCATION_TOOLKIT.DesEncrypt(INPUT_STRING=>INPUTSTRING,KEY_STRING=>KEYSTRING);
END DesEncrypt;
/
select DesEncrypt('11112abc' , '4578ccde') from dual ;

由于您使用的是 10g,您可能需要使用 DBMS_CRYPTO 包
http://www.stanford.edu /dept/itss/docs/oracle/10g/network.101/b10773/apdvncrp.htm

here you go, just let it know which overload to use by supplying the param names!

select DBMS_OBFUSCATION_TOOLKIT.DesEncrypt(INPUT_STRING=>'11112abc',KEY_STRING=>'4578ccde') 
from dual ;

returns

M5��w5Z

note, your key needs to be at least 8 bytes:

ORA-28234: key length too short
ORA-06512: at
"SYS.DBMS_OBFUSCATION_TOOLKIT_FFI",
line 21 ORA-06512: at
"SYS.DBMS_OBFUSCATION_TOOLKIT", line
126
28234. 00000 - "key length too short"
*Cause: The key specified is too short for the algorithm. DES
requires a key of at least 8 bytes. Triple DES requires a
key of least 16 bytes in two-key mode and 24 bytes in three-key
mode.
*Action: Specify a longer key.


You may always try it with a wrapper function (as tony suggested)

create or replace
function DesEncrypt(pinputString IN VARCHAR2 , pKeyString in VARCHAR2) RETURN varchar2
IS
BEGIN
return DBMS_OBFUSCATION_TOOLKIT.DesEncrypt(INPUT_STRING=>INPUTSTRING,KEY_STRING=>KEYSTRING);
END DesEncrypt;
/
select DesEncrypt('11112abc' , '4578ccde') from dual ;

Since you are on 10g, you may want to use the DBMS_CRYPTO package
http://www.stanford.edu/dept/itss/docs/oracle/10g/network.101/b10773/apdvncrp.htm

旧人九事 2024-11-11 22:54:47

这是使用旧版 dbms_obfuscation_toolkit 进行的加密/解密:

create or replace function crypt(p_str in varchar2, p_key in varchar2) return varchar2
as
  l_data varchar2(255);
begin
  l_data := rpad(p_str, (trunc(length(p_str)/8)+1)*8,chr(0));
  dbms_obfuscation_toolkit.DESEncrypt
  (input_string=>l_data,
  key_string=>p_key,
  encrypted_string=>l_data);

  return l_data;
end;

对于解密:

create or replace function decrypt(p_str in varchar2, p_key in varchar2) return varchar2
as
  l_data varchar2(255);
begin
  dbms_obfuscation_tookit.DESDecrypt
  (input_string=>p_str,
  key_string=>p_key,
  decrypted_string=>l_data);

  return rtrim(l_data,chr(0));
end;

以及用法:

declare

  l_data varchar2(100);
  l_key varchar2(100);
  l_encrypted varchar2(100);
  l_decrypted varchar2(100);

begin
  l_data := 'This is secret!!!';
  l_key := 'My secret key';
  dbms_output.put_line(l_data);

  l_encrypted := crypt(l_data, l_key);
  dbms_output.put_line(l_encrypted);

  l_decrypted := decrypt(l_encrypted, l_key);
  dbms_output.put_line(l_decrypted);

end;

here's a crypt/decrypt using the older dbms_obfuscation_toolkit:

create or replace function crypt(p_str in varchar2, p_key in varchar2) return varchar2
as
  l_data varchar2(255);
begin
  l_data := rpad(p_str, (trunc(length(p_str)/8)+1)*8,chr(0));
  dbms_obfuscation_toolkit.DESEncrypt
  (input_string=>l_data,
  key_string=>p_key,
  encrypted_string=>l_data);

  return l_data;
end;

And for decrypt:

create or replace function decrypt(p_str in varchar2, p_key in varchar2) return varchar2
as
  l_data varchar2(255);
begin
  dbms_obfuscation_tookit.DESDecrypt
  (input_string=>p_str,
  key_string=>p_key,
  decrypted_string=>l_data);

  return rtrim(l_data,chr(0));
end;

And usage:

declare

  l_data varchar2(100);
  l_key varchar2(100);
  l_encrypted varchar2(100);
  l_decrypted varchar2(100);

begin
  l_data := 'This is secret!!!';
  l_key := 'My secret key';
  dbms_output.put_line(l_data);

  l_encrypted := crypt(l_data, l_key);
  dbms_output.put_line(l_encrypted);

  l_decrypted := decrypt(l_encrypted, l_key);
  dbms_output.put_line(l_decrypted);

end;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文