Pavlin Penchev
Pavlin Penchev

Reputation: 21

My secret password in oracle won't output

I'm trying to output my procedure, with a secret password. When i try to run my code it doesn't work.

CREATE OR replace Procedure hiddenPasswords(
       p_MA_ID IN MitarbeiterAccounts.MitarbetierAccountID%TYPE,
       p_M_Login IN MitarbeiterAccounts.Mitarbeiter_Login%TYPE,
       p_M_Password IN MitarbeiterAccounts.Mitarbeiter_Password%TYPE)


IS
BEGIN

        INSERT INTO MitarbeiterAccounts(MitarbeiterAccountsID, 
         MitarbeiterAccounts_Login, Mitarbeiter_Password)
        VALUES(p_MA_ID, p_M_Login, HASHBYTES('SHA2_512', p_M_Password));

END;
/

EXEC hiddenPasswords p_MA_ID = 4, p_M_Login = 'Admin' p_M_Password = N'123';

I'm getting that HASHBYTES is invalid identifier

Upvotes: 1

Views: 132

Answers (1)

Arun Palanisamy
Arun Palanisamy

Reputation: 5459

Well, Oracle doesn't have any built-in function called HASHBYTES. It is there in SQL SERVER but not in Oracle

instead you can use DBMS_CRYPTO.HASH if you have that privilege for the same.

DBMS_CRYPTO provides an interface to encrypt and decrypt stored data, and can be used in conjunction with PL/SQL programs running network communications

DBMS_CRYPTO

Update

For eg., I have used RAW here. You can check other Overloaded functions in the above link where you can use BLOB, CLOB as well.

DECLARE
 l_pwd VARCHAR2(19) := 'mysecretpassword';
 l_ccn_raw RAW(128) := utl_raw.cast_to_raw(l_pwd);
 l_encrypted_raw RAW(2048);
BEGIN
  dbms_output.put_line('CC:  ' || l_ccn_raw);

  l_encrypted_raw := dbms_crypto.hash(l_ccn_raw, 1);
  dbms_output.put_line('MD4: ' || l_encrypted_raw);

  l_encrypted_raw := dbms_crypto.hash(l_ccn_raw, 2);
  dbms_output.put_line('MD5: ' || l_encrypted_raw);

  l_encrypted_raw := dbms_crypto.hash(l_ccn_raw, 3);
  dbms_output.put_line('SH1: ' || l_encrypted_raw);
END;
/

OUTPUT

CC:  6D7973656372657470617373776F7264
MD4: BBBA2CBC2F6E0F158D06B34F819DB5F6
MD5: 4CAB2A2DB6A3C31B01D804DEF28276E6
SH1: 08CD923367890009657EAB812753379BDB321EEB

Upvotes: 3

Related Questions