grant execute on dbms_crypto to USER_NAME;
−− 暗号化
CREATE OR REPLACE FUNCTION TEXT_ENCRYPT(pTXT VARCHAR2, pPwd VARCHAR2)
RETURN VARCHAR2
IS
vEncrypted RAW(1000);
BEGIN
vEncrypted := DBMS_CRYPTO.ENCRYPT(
src => UTL_I18N.STRING_TO_RAW (pTXT, 'AL32UTF8'),
typ => DBMS_CRYPTO.ENCRYPT_AES256 + DBMS_CRYPTO.CHAIN_CBC
+ DBMS_CRYPTO.PAD_PKCS5,
key => UTL_I18N.STRING_TO_RAW(RPAD(pPwd, 32, CHR(0)), 'AL32UTF8'));
RETURN UTL_RAW.CAST_TO_VARCHAR2(UTL_ENCODE.BASE64_ENCODE(vEncrypted));
END;
/
−− 復号化
CREATE OR REPLACE FUNCTION TEXT_DECRYPT(pEncTxt VARCHAR2, pPwd VARCHAR2)
RETURN VARCHAR2
IS
vRaw RAW(1000);
BEGIN
vRaw := UTL_ENCODE.BASE64_DECODE(UTL_RAW.CAST_TO_RAW(pEncTxt));
vRaw := DBMS_CRYPTO.DECRYPT(
src => vRaw,
typ => DBMS_CRYPTO.ENCRYPT_AES256 + DBMS_CRYPTO.CHAIN_CBC
+ DBMS_CRYPTO.PAD_PKCS5,
key => UTL_I18N.STRING_TO_RAW(RPAD(pPwd, 32, CHR(0)), 'AL32UTF8'));
RETURN UTL_I18N.RAW_TO_CHAR (vRaw, 'AL32UTF8');
END;
/
【このカテゴリーの最新記事】
- no image
- no image