Friday, June 13, 2014

encryption of password in Base64 and generating SHA-1 hash of it using pl/sql

The below sample query will encode the word PASSWORD into Base 64 and generates hash value in SHA-1 ,so that you can use this outcome to compare against the similar encoded passwords  in database.Typically this can be used in Authentication from any application.
SQL> select utl_raw.cast_to_varchar2(utl_encode.base64_encode(utl_raw.cast_to_raw(utl_raw.cast_to_varchar2(dbms_crypto.hash(utl_raw.cast_to_raw(‘PASSWORD’),3)))))
from dual;

User should have privileges to execute DBMS_CRYPTO and UTL_RAW functions in database.

Decryption of base-64 can be done in following way.

select utl_raw.cast_to_varchar2( utl_encode.base64_decode( utl_raw.cast_to_raw('FMDXURNTklTVFJBVE9S'))) decrypted_pwd from dual;

No comments:

Post a Comment