Need oracle function to convert string to byte array

I have a column:

LOGIN_PWD -> RAW(256 BYTE) 

I need to use an insert query to insert a hashed password string into this column. So, is there any oracle function that can hide the string in bytes, for example

 INSERT INTO TABLE_NAME (LOGIN_PWD) VALUES (convert.toBytes('hashed password')); 

I did this with a java program using the string.getBytes () method on my local machine, but for other applications I cannot use the same program to do this with a query

+4
source share
1 answer

If your requirement is as simple as you stated, you can use the UTL_RAW.CAST_TO_RAW function:

 INSERT INTO TABLE_NAME (LOGIN_PWD) VALUES (UTL_RAW.CAST_TO_RAW('hashed password')); 

Demo version of SQL Fiddle .

Using, for example, hashing a simple hashed string using Md5, which is 6a25a2b265d917ea91447daa81b2506d , the raw value stored in the table is:

 SELECT DUMP(LOGIN_PWD) FROM TABLE_NAME; DUMP(LOGIN_PWD) ------------------------------------------------------------------------------------------------------------------ Typ=23 Len=32: 54,97,50,53,97,50,98,50,54,53,100,57,49,55,101,97,57,49,52,52,55,100,97,97,56,49,98,50,53,48,54,100 

Which corresponds to what I get from getBytes() , on the same hashed value in Java.

If you want to return it to text for any reason, you can use UTL_RAW.CAST_TO_VARCHAR2 :

SELECT UTL_RAW.CAST_TO_VARCHAR2 (LOGIN_PWD) FROM TABLE_NAME;

 UTL_RAW.CAST_TO_VARCHAR2(LOGIN_PWD) ----------------------------------- 6a25a2b265d917ea91447daa81b2506d 
+8
source

Source: https://habr.com/ru/post/1483525/


All Articles