oracle数据库加密解密

CREATE OR REPLACE FUNCTION F_ENCRYPT_NUMBER(NUMBER_IN IN VARCHAR2)
  RETURN RAW IS
  NUMBER_IN_RAW RAW(128) := UTL_I18N.STRING_TO_RAW(NUMBER_IN, 'AL32UTF8');
  KEY_NUMBER    NUMBER(32) := 32432432343243279898;
  KEY_RAW       RAW(128) := UTL_RAW.CAST_FROM_NUMBER(KEY_NUMBER);
  ENCRYPTED_RAW RAW(128);
BEGIN
  ENCRYPTED_RAW := DBMS_CRYPTO.ENCRYPT(SRC => NUMBER_IN_RAW,
                                       TYP => DBMS_CRYPTO.DES_CBC_PKCS5,
                                       KEY => KEY_RAW);
  RETURN ENCRYPTED_RAW;
END;


SELECT F_ENCRYPT_NUMBER('www.xifenfei.com') FROM dual;
SELECT f_decrypt_number('01A9AB595EB7E9229167E53A1929044AE2AD0E69BA4D4D15') FROM dual;


CREATE OR REPLACE FUNCTION F_DECRYPT_NUMBER(ENCRYPTED_RAW IN RAW)
  RETURN VARCHAR2 IS
  DECRYPT_RAW RAW(48);
  KEY_NUMBER  NUMBER(32) := 32432432343243279898;
  KEY_RAW     RAW(128) := UTL_RAW.CAST_FROM_NUMBER(KEY_NUMBER);
BEGIN
  DECRYPT_RAW := DBMS_CRYPTO.DECRYPT(SRC => ENCRYPTED_RAW,
                                     TYP => DBMS_CRYPTO.DES_CBC_PKCS5,
                                     KEY => KEY_RAW);
  RETURN UTL_I18N.RAW_TO_CHAR(DECRYPT_RAW, 'AL32UTF8');
END;

 

posted on 2015-01-28 14:32  RainbowGu  阅读(1155)  评论(0编辑  收藏  举报

导航