Oracle Field 암호화 ( Encrypt and Decrypt )
For DBMS_OBFUSCATION_TOOLKIT, should execute follwing scripts as SYS
Building a Package
-->> 1. DECLARATION of Package
** Name : DBMS_OBFUSCATION_TOOLKIT
** Profile : 2 Procedures that can Encrypt/Decrypt the type VARCHAR2
2 Procedures that can Encrypt/Decrypt the type RAW
For DBMS_OBFUSCATION_TOOLKIT, should execute follwing scripts as SYS
-- Exection Scripts
SQL> @$ORACLE_HOME/rdbms/admin/dbmsobtk.sql
SQL> @$ORACLE_HOME/rdbms/admin/prvtobtk.plb
-- Granting
SQL> GRANT execute ON dbms_obfuscation_toolkit TO public;
Building a Package
CREATE OR REPLACE PACKAGE MSEncrypt AS
FUNCTION encrypt( Str VARCHAR2, hash VARCHAR2 ) RETURN VARCHAR2;
FUNCTION decrypt( xCrypt VARCHAR2, hash VARCHAR2 ) RETURN VARCHAR2;
END MSEncrypt;
/
-->> 2. Building BODY of Package
CREATE OR REPLACE PACKAGE BODY MSEncrypt AS
crypted_string VARCHAR2(2000);
FUNCTION encrypt( Str VARCHAR2, hash VARCHAR2 ) RETURN VARCHAR2 AS
pieces_of_eight INTEGER := ((FLOOR(LENGTH(Str)/8 + .9)) * 8);
BEGIN
DBMS_OBFUSCATION_TOOLKIT.DESENCRYPT(
input_string => RPAD( Str, pieces_of_eight ),
key_string => RPAD(hash,8,'#'),
encrypted_string => crypted_string
);
RETURN crypted_string;
END;
FUNCTION decrypt( xCrypt VARCHAR2, hash VARCHAR2 ) RETURN VARCHAR2 AS
BEGIN
DBMS_OBFUSCATION_TOOLKIT.DESDECRYPT(
input_string => xCrypt,
key_string => RPAD(hash,8,'#'),
decrypted_string => crypted_string
);
RETURN trim(crypted_string);
END;
END MSEncrypt;
/
===>>>> TEST Example
1. Generate Table
CREATE TABLE EJDEV.TESTAGENT
(
AGENTID NUMBER(10) NOT NULL,
AGENTNAME VARCHAR2(64 BYTE) NOT NULL,
PASSWORDL VARCHAR2(64 BYTE), --- 입력할 암호의 길이를 제한한다. ( Length limited )
PASSWORDS VARCHAR2(10 BYTE) --- 입력할 암호의 길이를 제한한다.
--- Key 로 사용하는 hash 값은 큰 제한이 없다.
--- Key 로 사용하는 hash 값은 큰 제한이 없다.
)
2. Insert Data into Table using Package.Fuction including DBMS_OBFUSCATION_TOOLKIT
I will put the data encrypted with Function into table
Insert Into TestAgent ( AgentID
, AgentName
, PasswordL
, PasswordS
)
, AgentName
, PasswordL
, PasswordS
)
Values ( 3
,'TestID'
, MSEncrypt.encrypt('pword','ishashkey')
, MSEncrypt.encrypt('pword', '12345')
)
,'TestID'
, MSEncrypt.encrypt('pword','ishashkey')
, MSEncrypt.encrypt('pword', '12345')
)
;
Commit
;
3. Select Data from the Table.
Select AgentID, AgentName
, PasswordL
, PasswordL
, MSEncrypt.decrypt(PasswordL, 'ishashkey') resultwithrightkey
, PasswordS
, MSEncrypt.decrypt(PasswordS, 'withwrongkey') resultwithwrongkey
from TestAgent
Where AgentID = 3
Where AgentID = 3
It shows as follwings.
Got it !!
Reference : http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:685421699413 http://www.oracleclub.com/lecture/1200
integer : 정수, 완전체, 완전한 것
'Oracle' 카테고리의 다른 글
MSSQL 테이블 정보 조회 (0) | 2011.06.05 |
---|---|
Materialized View Refresh Option (0) | 2011.06.05 |
Oracle 복구 관련 (0) | 2011.05.08 |
Oracle Lock (0) | 2011.05.03 |
Read Consistency (0) | 2011.05.03 |