How to perform a password BCRYPT hashing on Oracle?

What I need

  • I need SQL similar to encodePassword does as in symfony in Oracle.

  • I tried to find encryption string using SHA512 which give me very length string.

Symfony code

public function encodePassword(UserInterface $user, $plainPassword)
{
   encoder = $this->encoderFactory->getEncoder($user);
   $plainPassword='hello world';
   return $encoder->encodePassword($plainPassword, $user->getSalt());
}

Give me output

Example $2y$13$u5wqc1JNqFv1F4JXlmXbCORFU1./s/6HslG79q4tk3YLSBD..ihmi

PHP snippet

echo password_hash ("rasmuslerdorf", PASSWORD_DEFAULT);
// $2y$10$.vGA1O9wmRjrwAVXD98HNOgsNpDczlqm3Jq7KnEd1rVAGv3Fykk1a

Oracle snippet

                   declare
              p_string varchar2(2000) := 'hello world';
              lv_hash_key_sh512   raw (1000);
              lv_varchar_key_sh512   varchar2 (32000);
            begin
            
                lv_hash_key_sh512 :=
                 dbms_crypto.hash (src   => utl_raw.cast_to_raw (p_string),
                                   typ   => dbms_crypto.HASH_SH512);
            
              -- convert into varchar2
              select   lower (to_char (rawtohex (lv_hash_key_sh512)))
                into   lv_varchar_key_sh512
                from   dual;
            
            
              dbms_output.put_line('String to encrypt : '||p_string);
              dbms_output.put_line('SHA512 encryption : '||lv_varchar_key_sh512);
            end;

Output
SHA512 encryption: 8d29c8ecbe0f17756f7b1e86c1307a09f5825be85049f607cf952f0d788

  • I need password encryption in Oracle so that symfony fos user bundle will accept the password.

Reference
https://docs.oracle.com/database/121/ARPLS/d_crypto.htm#ARPLS65675

Source: Symfony Questions

Was this helpful?

0 / 0

Leave a Reply 0

Your email address will not be published. Required fields are marked *