DECLARE
v_password_1 VARCHAR2(240);
v_password_2 VARCHAR2(240);
v_password_3 VARCHAR2(240);
BEGIN
v_password_1 := 'CxY-1234567-AbC';
dbms_output.put_line('加密前:' || v_password_1);
--加密
v_password_2 := cux_password_demo.password_encrypt(p_passwd => v_password_1);
dbms_output.put_line('加密后:' || v_password_2);
--解密
v_password_3 := cux_password_demo.password_decrypt(p_passwd => v_password_2);
dbms_output.put_line('解密后:' || v_password_3);
END;
CREATE OR REPLACE PACKAGE cux_password_demo AS
/*==================================================
-- Author : CXY5632
-- Created : 2014/2/20 18:04:03
-- Purpose : 密码加密解密演示
==============================================*/
FUNCTION decrypt(key IN VARCHAR2, VALUE IN VARCHAR2) RETURN VARCHAR2;
FUNCTION encrypt(key IN VARCHAR2, VALUE IN VARCHAR2) RETURN VARCHAR2;
FUNCTION password_encrypt(p_passwd IN VARCHAR2) RETURN VARCHAR2;
FUNCTION password_decrypt(p_passwd IN VARCHAR2) RETURN VARCHAR2;
END cux_password_demo;
/
CREATE OR REPLACE PACKAGE BODY cux_password_demo AS
/*==================================================
-- Author : CXY5632
-- Created : 2014/2/20 18:04:03
-- Purpose : 密码加密解密演示
==============================================*/
FUNCTION decrypt(key IN VARCHAR2, VALUE IN VARCHAR2) RETURN VARCHAR2 AS
LANGUAGE JAVA NAME 'oracle.apps.fnd.security.WebSessionManagerProc.decrypt(java.lang.String,java.lang.String) return java.lang.String';
FUNCTION encrypt(key IN VARCHAR2, VALUE IN VARCHAR2) RETURN VARCHAR2 AS
LANGUAGE JAVA NAME 'oracle.apps.fnd.security.WebSessionManagerProc.encrypt(java.lang.String,java.lang.String) return java.lang.String';
/* =============================================
* FUNCTION
* NAME :
* password_decrypt
* DESCRIPTION:
* 暗文解密
* ARGUMENT:
* p_passwd : 需要解密的暗文解密
* RETURN:
*
* HISTORY:
* 1.00 2014-02-20 cxy Creation
* =============================================*/
FUNCTION password_decrypt(p_passwd IN VARCHAR2) RETURN VARCHAR2 IS
l_decrypted_passwd VARCHAR2(100);
BEGIN
SELECT decrypt((SELECT (SELECT decrypt(fnd_web_sec.get_guest_username_pwd,
usertable.encrypted_foundation_password)
FROM dual) AS apps_password
FROM apps.fnd_user usertable
WHERE usertable.user_name =
(SELECT substr(fnd_web_sec.get_guest_username_pwd,
1,
instr(fnd_web_sec.get_guest_username_pwd,
'/') - 1)
FROM dual)),
p_passwd)
INTO l_decrypted_passwd
FROM dual;
RETURN l_decrypted_passwd;
EXCEPTION
WHEN OTHERS THEN
RAISE fnd_api.g_exc_unexpected_error;
END password_decrypt;
/* =============================================
* FUNCTION
* NAME :
* password_encrypt
* DESCRIPTION:
* 明文加密
* ARGUMENT:
* p_passwd : 需要加密的明文
* RETURN:
*
* HISTORY:
* 1.00 2014-02-20 cxy Creation
* =============================================*/
FUNCTION password_encrypt(p_passwd IN VARCHAR2) RETURN VARCHAR2 IS
l_encrypted_passwd VARCHAR2(100);
BEGIN
SELECT encrypt((SELECT (SELECT decrypt(fnd_web_sec.get_guest_username_pwd,
usertable.encrypted_foundation_password)
FROM dual) AS apps_password
FROM apps.fnd_user usertable
WHERE usertable.user_name =
(SELECT substr(fnd_web_sec.get_guest_username_pwd,
1,
instr(fnd_web_sec.get_guest_username_pwd,
'/') - 1)
FROM dual)),
p_passwd)
INTO l_encrypted_passwd
FROM dual;
RETURN l_encrypted_passwd;
EXCEPTION
WHEN OTHERS THEN
RAISE fnd_api.g_exc_unexpected_error;
END password_encrypt;
END cux_password_demo;
/