ult_i18n.string_to_raw

Hi all

I try to use the package dbms_crypto to encrypt and decrypt data. Here is the code of my package that I wrote:

create or replace package body encdec_crypto
as
  l_num_key_bytes number := 32;
  l_key_bytes raw(32) := dbms_crypto.randombytes(l_num_key_bytes);
  l_type pls_integer := dbms_crypto.encrypt_aes256
  + dbms_crypto.chain_cbc
  + dbms_crypto.pad_pkcs5;

  function encrypt_pwd(
  p_text varchar2
  )
  return raw
  is
  l_encrypted_data raw(2000);
  begin
  l_encrypted_data := dbms_crypto.encrypt(
  src => ult_i18n.string_to_raw(p_text, 'AL32UTF8')
  , typ => l_type
  , key => l_key_bytes
  );
  return l_encrypted_data;
  end encrypt_pwd;


  function decrypt_pwd(
  p_raw raw
  )
  return varchar2
  is
  l_decrypted_data raw(2000);
  begin
  l_decrypted_data := dbms_crypto.decrypt(
  src => p_raw
  , typ => l_type
  , key => l_key_bytes
  );
  return utl_i18n.raw_to_char(l_decrypted_data, 'AL32UTF8');
  end decrypt_pwd;
end encdec_crypto;
/
show err

Initially when I tried to compile this code, it gave me error on dbms_crypto package as an invalid identifier, then I gave run command this procedure to my sys user, then it shows me following error on function utl_i18n.string_to_raw

Warning: Package Body created with compilation errors.


Errors for PACKAGE BODY ENCDEC_CRYPTO:


LINE/COL ERROR
-------- -----------------------------------------------------------------
16/3     PL/SQL: Statement ignored
17/13    PLS-00201: identifier 'ULT_I18N.STRING_TO_RAW' must be declared
jagdeep@css>

I gave permission for this package execute also this user as follows:

SQL> grant execute on dbms_crypto to jagdeep;
Grant succeeded.
SQL> grant execute on utl_i18n to jagdeep;
Grant succeeded.

Kindly help me on this point, what I'm missing here

Concerning

Jagdeep Seven

My version is

BANNER

----------------------------------------------------------------

Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - 64bi

PL/SQL Release 10.2.0.1.0 - Production

CORE 10.2.0.1.0 Production

AMT for Linux: Version 10.2.0.1.0 - Production

NLSRTL Version 10.2.0.1.0 - Production

It's not ULT_I18N its _I18N UTL

Also encryption of password in not a good idea. You would be better of chop.

Tags: Database

Similar Questions

  • Dbms_Crypto.encrypt

    Hi all

    I will encrypt and decrypt a particular value of number using "SHA-1 Message Authentication Code.

    I was planning to use dbms_crypto.encrypt using HMAC_SH1 users must use the same key for encryption and decryption, but seems using other key for decryption users were able to decrypt the passed string. What's wrong with the code below?

    The Oracle documentation reference: http://docs.oracle.com/cd/B28359_01/appdev.111/b28419/d_crypto.htm

    PLSQL Code:

    -------------------------------------------------------------

    DECLARE

    input_string VARCHAR2 (200): = '123456'.

    l_encrypt_key VARCHAR2 (2000): = '1215181167716155195232915411';

    l_decrypt_key VARCHAR2 (2000): = '1215181167716154262212312345';

    output_string VARCHAR2 (200);

    encrypted_raw RAW (2000);             -stores the encrypted binary text

    decrypted_raw RAW (2000);             -stores the decrypted binary text

    key_bytes_raw RAW (32);               -stores the encryption key

    encryption_type PLS_INTEGER: = encryption suite - type total encryption.

    DBMS_CRYPTO. HMAC_SH1 + DBMS_CRYPTO. CHAIN_CBC + DBMS_CRYPTO. PAD_PKCS5;

    BEGIN

    DBMS_OUTPUT. Put_line ("original string: ' |") input_string);

    key_bytes_raw: = UTL_I18N. STRING_TO_RAW (l_encrypt_key, "AL32UTF8"); ---

    DBMS_OUTPUT. Put_line (' key bytes Raw string: ' | key_bytes_raw);

    encrypted_raw: = DBMS_CRYPTO. ENCRYPT

    (

    SRC = > UTL_I18N. STRING_TO_RAW (input_string 'AL32UTF8'),

    Typ = > encryption_type,.

    key = > key_bytes_raw

    );

    DBMS_OUTPUT. Put_line (' Raw encrypted string: ' | encrypted_raw);

    -The encrypted value 'encrypted_raw' can be used here

    key_bytes_raw: = UTL_I18N. STRING_TO_RAW (l_decrypt_key, "AL32UTF8"); ---

    DBMS_OUTPUT. Put_line (' key bytes Raw string: ' | key_bytes_raw);

    decrypted_raw: = DBMS_CRYPTO. DECRYPT

    (

    SRC = > encrypted_raw,

    Typ = > encryption_type,.

    key = > key_bytes_raw

    );

    DBMS_OUTPUT. Put_line (' Raw decrypted string: ' | decrypted_raw);

    output_string: = UTL_I18N. RAW_TO_CHAR (decrypted_raw, "AL32UTF8");

    DBMS_OUTPUT. Put_line (' decoded string: ' | output_string);

    END;

    /

    Output:

    --------------------------------------

    Original string: 123456

    Key Raw bytes string: 31323135313831313637373136313535313935323332393135343131

    Encrypted raw string: 8F4B3B0F9FAA77D7

    Key Raw bytes string: 31323135313831313637373136313534323632323132333132333435

    Decrypted raw string: 313233343536

    Decrypted string: 123456

    There are a LOT of Oracle documentation with examples of use of encryption and hash. Here is one of them.

    Development of Applications using the encryption of data API - 11 g Release 2 (11.2)

    Example of AES 256 bits encryption and decryption of the procedures

    The following PL/SQL block shows how to encrypt and decrypt a predefined variable named input_string using the 256-bit AES with Cipher Block Chaining and #5 PKCS padding algorithm.

  • The name of the reg file. output BI Publisher burst by e-mail

    Hello

    I developed a report that breaks out the statement of account and offers to the customers by e-mail. It delivers the with the name of the file 'xmlp6264966643117343570tmp_0010003063003001_5'.pdf. The name account account number. I would like to change it to just "account_statement".pdf.

    Please help and I would like to know how can I achieve this.

    Concerning

    Prasanna

    Hello

    If someone uses BI Publisher 10 g for burst yet, they can use the hash function in SQL and apply the same on the KEY column in the bursting of query and the query report so that the output being sent by electronic mail file will not have the real key in it.

    An example is as below ' rawtohex (DBMS_CRYPTO. Hash (UTL_I18N. STRING_TO_RAW (CCA. CUST_AC_NO, 'AL32UTF8'), 2)) '

  • PasswordDeriveBytes for PL/SQL

    How to implement PasswordDeriveBytes (c#) in Oracle PL/SQL? Many examples are in Java or c#.

    Kind regards.

    You started this thread saying you know many implementations in c# and java. How is possible to convert one of these examples of pl/sql?

    If I take the first link I find using https://www.google.com/?gws_rd=ssl#newwindow=1&q=PasswordDeriveBytes+java , http://stackoverflow.com/questions/21480202/encryption-result-in-java-and-net-are-not-same I see a java implementation. And transformed into pl/sql.

      function PasswordDeriveBytes
        ( passPhrase varchar2
        , saltValue raw
        , hashAlgorithm varchar2 := 'SHA1'
        , iterations pls_integer := 100
        , len pls_integer := null
        )
      return raw
      is
        rv raw(1000);
        tmp raw(1000);
        htype pls_integer := case hashAlgorithm
                               when 'MD5'  then dbms_crypto.hash_md5
                               when 'SHA1' then dbms_crypto.hash_sh1
                             end;
      begin
        tmp := dbms_crypto.hash( utl_raw.concat( utl_i18n.string_to_raw( passPhrase )
                                               , saltValue
                                               )
                               , htype
                               );
        for i in 1 .. iterations - 2
        loop
          tmp := dbms_crypto.hash( tmp, htype );
        end loop;
        rv := dbms_crypto.hash( tmp, htype );
        if len is not null
        then
          for i in 1 .. trunc( ( len - 1 ) / utl_raw.length( rv ) )
          loop
            rv := utl_raw.concat( rv, dbms_crypto.hash( utl_raw.concat( utl_raw.cast_to_raw( i ), tmp ), htype ) );
          end loop;
          rv := utl_raw.substr( rv, 1, len );
        end if;
        return rv;
      end;
    

    Two minutes

  • Encrypt and decrypt using the key of the table

    Dear Experts,

    Here is my package to encrypt and decrypt with triples in oracle 11 g.

    In my package, I used encryption_key (3FECCDC7D348A85B096F0B43C4C6A38DBBD369DB37FEA435) according to this key we are encryption and decryption.

    My requirement is now, I don't want to spend the encryption_key in my code.we key stored in a table (key_details) and using the key column, we her encrypt and decrypt the data.

    -----------------------------------

    create the table key_details

    (

    Identification number,

    VARCHAR2 (48) key

    );

    insert into key_details values(1,'3FECCDC7D348A85B096F0B43C4C6A38DBBD369DB37FEA435');

    -------------------------------------

    CREATE or REPLACE PACKAGE encr_decr

    AS

    FUNCTION encrypt (p_plainText VARCHAR2) RETURN RAW DETERMINISTIC;

    FUNCTION decrypt (p_encryptedText RAW) RETURN VARCHAR2 DETERMINISTIC;

    END;

    /

    CREATE or REPLACE PACKAGE encr_decr BODY

    AS

    encryption_type PLS_INTEGER: = DBMS_CRYPTO. ENCRYPT_3DES

    + DBMS_CRYPTO. CHAIN_ECB

    + DBMS_CRYPTO. PAD_PKCS5;

    encryption_key RAW (48): = UTL_RAW.cast_to_raw ('3FECCDC7D348A85B096F0B43C4C6A38DBBD369DB37FEA435');

    FUNCTION encrypt (p_plainText VARCHAR2) RETURN RAW DETERMINISTIC

    IS

    encrypted_raw RAW (2000);

    BEGIN

    encrypted_raw: = DBMS_CRYPTO. ENCRYPT

    (

    SRC = > UTL_RAW. CAST_TO_RAW (p_plainText),

    Typ = > encryption_type,.

    key = > encryption_key

    );

    RETURN encrypted_raw;

    END encrypt;

    FUNCTION decrypt (p_encryptedText RAW) RETURN VARCHAR2 DETERMINISTIC

    IS

    decrypted_raw RAW (2000);

    BEGIN

    decrypted_raw: = DBMS_CRYPTO. DECRYPT

    (

    SRC = > p_encryptedText,

    Typ = > encryption_type,.

    key = > encryption_key

    );

    RETURN (UTL_RAW. CAST_TO_VARCHAR2 (decrypted_raw));

    END decrypt;

    END;

    /

    Help, please.

    create or replace package body encr_decr

    as

    encryption_type pls_integer: = dbms_crypto.encrypt_3des

    + dbms_crypto.chain_ecb

    + dbms_crypto.pad_pkcs5;

    gross encryption_key (48);

    --

    function encrypt (p_plaintext varchar2)

    gross return deterministic

    is

    Start

    Return dbms_crypto.encrypt (CBC-online utl_i18n.string_to_raw (p_plaintext)

    typ-online encryption_type

    key-online encryption_key

    );

    end encrypt;

    --

    function decrypt (gross p_encryptedtext) return varchar2 deterministic

    is

    Start

    Return utl_i18n.raw_to_char (dbms_crypto.decrypt (src-online p_encryptedtext

    typ-online encryption_type

    key-online encryption_key

    )

    );

    put an end to decrypt;

    Start

    Select the key in encryption_key

    of key_details

    where id = 1;

    end;

    /

  • How to authenticate with dbms_crypto

    Hi, I use 11.2.0.4 database and 4.0.3.16 SQL Developer to build the application in the 4.2.5.00.08 APEX. So far I've always used the APEX of authentication or service AD. I would like to create a new scheme of personal authentication with encrypted passwords, using a PL/SQL package. I copied and pasted most of this from discussion threads. I always wanted to be a programmer, alas, my hopes are fading. I know that you people can do this in your sleep. I can create the user and encrypt the password, however, I can not authenticate on the encrypted password. Can I have mucked cela up while trying different threads. I think the problem is the process on the page, or I can not be in the way of the correct settings. P101_PASSWORD is a type of password to APEX. When I have a comment - AND student_password = v_hash, it works, but of course, he don't know the password. I appreciate the tips.

    Peter

    DECLARE

    Result number: = 0;

    BEGIN

    result: = AUTH_PKG.authenticate_user (p_user_name_in = >: P101_USERNAME, p_password_in = >: P101_PASSWORD);

    IF (result = 0)

    THEN

    wwv_flow_custom_auth_std.post_login

    (P_UNAME = >: P101_USERNAME,)

    P_PASSWORD = >: P101_PASSWORD,.

    P_SESSION_ID = > v ('APP_SESSION').

    P_FLOW_PAGE = >: APP_ID | » :1');

    ON THE OTHER

    owa_util. REDIRECT_URL ('f? p = & APP_ID.:101: & SESSION.) ") ;

    END IF;

    END;

    The error is... additional_info: ORA-20001: year XXX tainted to authenticate the user - ORA-06502: PL & #x2F; SQL: a digital error or value: hex to raw conversion error

    CREATE TABLE 'STUDENT '.

    (NUMBER OF 'STUDENT_ID',

    VARCHAR2 (100 BYTE) "E-MAIL."

    VARCHAR2 (100 BYTE) "STUDENT_PASSWORD."

    'STUDENT_PK' CONSTRAINT PRIMARY KEY ('STUDENT_ID")

    create or replace the BODY of PACKAGE 'AUTH_PKG' AS

    PROCEDURE adduser (p_user_name_in IN student.email%TYPE, p_password_in IN student.student_password%TYPE)
    is
    v_pwd_hash varchar2 (2000);
    Start
    v_pwd_hash: = get_enc_val (p_password_in, 'AL32UTF8');
    insert into student (e-mail, student_password) values (p_user_name_in, v_pwd_hash);
    commit;
    adduser end;

    FUNCTION authenticate_user (p_user_name_in IN student.email%TYPE, p_password_in IN student.student_password%TYPE)
    RETURN number
    IS
    l_username student.email%TYPE: = p_user_name_in;
    l_password student.student_password%TYPE: = p_password_in;
    l_count NUMBER: = 0;
    v_hash varchar2 (2000);

    BEGIN
    v_hash: = get_dec_val (p_password_in, 'AL32UTF8');
    SELECT count (*)
    IN l_count
    The STUDENT
    WHERE UPPER (email) = UPPER (l_username)
    AND student_password = v_hash
    AND NVL (num_invalid_logins, 0) < l_max_failed_logins;.
    IF l_count = 1 THEN
    apex_util.set_session_state ('USERNAME', UPPER (l_username));
    apex_util.set_session_state ('LOGIN_MESSAGE', 'count = 1');
    reset_invalid_login_count (l_username);
    RETURN 1;
    ON THE OTHER
    apex_util.set_session_state ('LOGIN_MESSAGE', ' count <>1');
    update_invalid_login_count (l_username);
    l_failed_logins_count: = GET_NUM_INVALID_LOGINS (l_username);
    IF l_failed_logins_count > l_max_failed_logins THEN
    lock_user_account (l_username);
    apex_util.set_session_state ('LOGIN_MESSAGE', 'your account has been locked.');
    END IF;
    RETURN 0;
    END IF;
    EXCEPTION
    WHILE OTHERS THEN
    RAISE_APPLICATION_ERROR (-20001, ' XXX is an error produced to authenticate-' |) SQLERRM);
    END authenticate_user;

    function get_enc_val (p_in in flood, in the first p_key) gross return is
    l_enc_val varchar2 (2000);
    number of l_mod: = dbms_crypto. ENCRYPT_AES128 + dbms_crypto. CHAIN_CBC + dbms_crypto. PAD_PKCS5;
    Start
    l_enc_val: = dbms_crypto.encrypt (UTL_I18N. STRING_TO_RAW(p_in,'AL32UTF8'), l_mod, p_key);
    Return l_enc_val;
    end;

    function get_dec_val (p_in in flood, p_key in raw) gross yield
    is
    gross l_ret (2000);
    gross l_dec_val (2000);
    number of l_mod: = dbms_crypto. ENCRYPT_AES128 + dbms_crypto. CHAIN_CBC + dbms_crypto. PAD_PKCS5;
    Start
    l_dec_val: = dbms_crypto.decrypt(p_in,l_mod,p_key);
    l_ret: = UTL_I18N. RAW_TO_CHAR (l_dec_val, 'AL32UTF8');
    Return l_ret;
    end;

    END AUTH_PKG;

    Post edited by: Hi 2775296, the original message was get_enc_val (p_in in varchar2, p_key in the first). I tried to change the data types from raw to varchar2 and varchar2 to raw, but I'm not sure who should be believed or varchar2. I got the same result. I also tried to change the v_hash: = get_dec_val (p_password_in, 'AL32UTF8'); to v_hash: = get_enc_val (p_password_in, 'AL32UTF8'); I got the same result. I don't think that get_dec_val is needed for this. No explanation is useful. Thank you. Peter

    Store your password like a brute, for raw (100) of the instance

    And you can try something like

    create or replace package body auth_pkg

    as

    --

    function hash_pw (p_pw varchar2, varchar2 p_salt)

    Return to raw

    is

    t_pw raw (200);

    t_salt raw (200);

    t_tmp raw (204);

    T_T raw (20);

    t_hpw raw (100);

    Start

    If utl_raw.length (utl_raw.cast_to_raw (substr (p_pw, 1, 800))) > 200

    then

    t_pw: = utl_raw.substr (utl_raw.cast_to_raw (substr (p_pw, 1, 800)), 1, 200);

    on the other

    t_pw: = utl_raw.cast_to_raw (p_pw);

    end if;

    If utl_raw.length (utl_raw.cast_to_raw (substr (p_salt, 1, 800))) > 200

    then

    t_salt: = utl_raw.substr (utl_raw.cast_to_raw (substr (p_salt, 1, 800)), 1, 200);

    on the other

    t_salt: = utl_raw.cast_to_raw (p_salt);

    end if;

    because me in 1... 5

    loop

    t_tmp: = utl_raw.concat (t_salt, to_char (i, 'fm0xxxxxxx'));

    for c in 1... 1024

    loop

    t_tmp: = dbms_crypto.mac (t_tmp, dbms_crypto.hmac_sh1, t_pw);

    If c = 1

    then

    T_T: = t_tmp;

    on the other

    T_T: = utl_raw.bit_xor (t_t, t_tmp);

    end if;

    end loop;

    t_hpw: = utl_raw.concat (t_hpw, t_t).

    end loop;

    Return t_hpw;

    end;

    --

    procedure adduser

    (p_user_name_in to student.email%type

    p_password_in in student.student_password%type

    )

    is

    v_pwd_hash raw (100);

    Start

    v_pwd_hash: = hash_pw (p_password_in, bass (p_user_name_in));

    insert into student (e-mail, student_password) values (p_user_name_in, v_pwd_hash);

    end;

    --

    function authenticate_user

    (p_user_name_in to student.email%type

    p_password_in in student.student_password%type

    )

    Return number

    is

    number of l_max_failed_logins: = 10;

    cursor c_usr (gross b_hash)

    is

    Select 1 model

    the student

    where superior (e-mail) = upper (p_user_name_in)

    and student_password = v_pwd_hash

    and nvl (num_invalid_logins, 0)<>

    r_usr c_usr % rowtype;

    l_found boolean;

    Start

    Open c_usr (hash_pw (p_password_in, bass (p_user_name_in));)

    extract the c_usr in r_usr;

    l_found: = c_usr % found;

    close c_usr;

    --

    If l_found

    then

    apex_util.set_session_state ("username", upper (p_user_name_in));

    apex_util.set_session_state ('login_message', 'count = 1');

    reset_invalid_login_count (p_user_name_in);

    on the other

    apex_util.set_session_state ('login_message', ' County<>1');

    update_invalid_login_count (p_user_name_in);

    If (p_user_name_in) get_num_invalid_logins > l_max_failed_logins

    then

    lock_user_account (p_user_name_in);

    apex_util.set_session_state ('login_message', "your account has been locked.");

    end if;

    end if;

    refer the case back when end t_found then 1 0 otherwise;

    end;

    --

    end;

  • Write a Get_bit function

    Hello

    I have a get_bit function in the Postgres database.  In Oracle, there is no built-in function to manage the get_bit.    I need to write my custom Oracle PLSQL function to mimic the behavior of this get_bit function.  Can we have suggestions on how to do it?   Thank you!

    Get_bit definition is as follows:

    Function

    Return type

    Description

    Example of

    Result

    GET_BIT (String, offset)

    int

    Excerpt from bit string

    GET_BIT (E 'Th\\000omas': bytea, 45)

    1

    GET_BIT (String, offset)(returns int)
    Excerpt from bit string
    GET_BIT (E 'Th\\000omas': bytea, 45) = > 1

    Note that the bits in a byte are numbered with the least significant bit being the bit to zero. In the example above, the 'a' is the

    byte that is referenced and it contains x '61' = > 0110 0001 and the third bit from left to right (bit 5 from scratch at right) is returned.

    I don't know if you need a VARCHAR2 string as input or directly a byte sequence so here's an example that accepts an input VARCHAR2 and an argument optional charset to convert the string in bytes (default is the database character set).

    SQL> create or replace function get_bit (
      2    p_str     in varchar2
      3  , p_bit_num in integer
      4  , p_cs      in varchar2 default null
      5  )
      6  return integer deterministic
      7  is
      8    input        raw(32767) := utl_i18n.string_to_raw(p_str, p_cs);
      9    target_byte  raw(1);
     10    output       integer;
     11  begin
     12    target_byte := utl_raw.substr(input, trunc(p_bit_num/8)+1, 1);
     13    output := bitand(utl_raw.cast_to_binary_integer(target_byte) / power(2, mod(p_bit_num, 8)), 1);
     14    return output;
     15  end;
     16  /
    
    Function created
    
    SQL>
    SQL> select get_bit('Th'||chr(0)||'omas', 45)
      2  from dual;
    
    GET_BIT('TH'||CHR(0)||'OMAS',4
    ------------------------------
                                 1
    
  • How to add a number to a tank?

    Hi all

    11.2.0.3.11

    AIX6

    I want to blur a PAN (char10) by inverting it and add 1.

    for example: if my pan is 0010000000 = 0000000101

    But if I run

    Select reverse (pan) + 1 of test2;

    101

    The result is truncated.

    Help, please

    Thank you very much

    MK

    Here's an example that uses the hash. Hashes however has no resemblance to the original data type (e.g., number), or the size of the original type. However, it is very robust and almost impossible to return to its initial value (it can not be decrypted as it is not an encrypted value):

    SQL> create or replace function HashToken( token string ) return varchar2 is
      2          hashRaw        raw(200);
      3  begin
      4          hashRaw := DBMS_CRYPTO.Hash(
      5                  src => UTL_I18N.string_to_raw( token,  'AL32UTF8'),
      6                  typ => DBMS_CRYPTO.HASH_SH1
      7          );
      8          return(
      9                  UTL_RAW.cast_to_varchar2(
    10                          UTL_ENCODE.base64_encode( hashRaw )
    11                  )
    12          );
    13  end;
    14  /
    
    Function created.
    
    SQL>
    SQL> select empno, hashToken(empno) as EMPNO_2, ename, hashToken(ename) as ENAME_2 from emp;
    
        EMPNO EMPNO_2                        ENAME      ENAME_2
    ---------- ------------------------------ ---------- ------------------------------
          7369 j/Q9fKLPQ6dCVX8WVnrO58BR4k4=  SMITH      vHC+fzgEbmTdd58nbOSiD5kVPyY=
          7499 rRJNLGFCLljjoyCDgY6ApawJSZ8=  ALLEN      bhyulhEv4kncD7T5oATJ3AQxVgg=
          7521 JvRFANpJd/kA3EByBKSEHEzNhMM=  WARD      fH8yQl+gdsru2XH1VJyC/6iP0Os=
          7566 aPQt5PUO42M5ld3tql46s/4dkrw=  JONES      oXhzUyATAtZcdESGwelAcJ/uDv8=
          7654 BvuWQZCZ3jbVDyIb58+BK1BI35E=  MARTIN    87m4ei83fABuk18y3SXqVev39VE=
          7698 lVTy4fuRuKS6r2YPwoiJAKKWvzc=  BLAKE      fN5Vs6bpz2ENsgC2ucybWtyhZX8=
          7782 yMQ93RpW9dkhmvk8PNgKv+B3BC4=  CLARK      T5DhA/rK3QeH16aCjwlvbmZZWkc=
          7788 5lb3Wwnh30yxrL+IcGL20gOZmGU=  SCOTT      djT9yAqkAnz9XpZqvBtrS06hn74=
          7839 T+/M/+ljq9VtNWQ1OPHHXgwM2Y0=  KING      ULijOfgquc5sVb+OoQ2thRPp0UI=
          7844 1KTe23LiAsS+aiR+/4e53kYVr7E=  TURNER    4EPj0+vdr6pe2X99zE0jYob4rUo=
          7876 Xw8u1RpZIsHOGawJepxO7vVxpr0=  ADAMS      LS6yfh24g25EzU6U9YuJcoMx6N4=
          7900 NNUKH1bET552ol04d4qdqStL8n4=  JAMES      avxErzy9u2cY6NqHFaGVa4ldxdI=
          7902 090VmzHaIzD15LmqG6uZg2ttPRk=  FORD      flsH2Lu14KVbXUKEdtRpGz7pe0o=
          7934 g4zo8/4ZT6Zw0UTXOMZdKSdfLBw=  MILLER    JdWuOw4NrFEbqU4ze4jgiHU4sx8=
    
    14 rows selected.
    
    SQL>
    

    This hash really won't work for columns that are not varchar, or too small.

    An alternative is to use a sequence in a mapping table. The table mapping maps a PAN such as a sequence value. Then use the mapping table to replace all the column values of PAN with sequence values - while maintaining referential integrity and so on. For example

    SQL> create table mapping(
      2          old_empno primary key,
      3          new_empno
      4  ) organization index
      5  nologging as
      6  select empno, rownum from emp;
    
    Table created.
    
    SQL>
    SQL> select * from mapping;
    
     OLD_EMPNO  NEW_EMPNO
    ---------- ----------
          7369          1
          7499          2
          7521          3
          7566          4
          7654          5
          7698          6
          7782          7
          7788          8
          7839          9
          7844         10
          7876         11
          7900         12
          7902         13
          7934         14
    
    14 rows selected.
    
    SQL>
    SQL> create table dev_emp
      2  nologging as
      3  select
      4          cast(e.new_empno as number(4)) as EMPNO,
      5          s.ename,
      6          s.job,
      7          cast(m.new_empno as number(4)) as MGR,
      8          s.hiredate,
      9          s.sal,
     10          s.comm,
     11          s.deptno
     12  from       emp s,       -- source
     13          mapping e,      -- id for employees
     14          mapping m       -- id for managers
     15  where      s.empno = e.old_empno
     16  and        s.mgr = m.old_empno (+);
    
    Table created.
    
    SQL>
    SQL> select * from emp order by ename;
    
         EMPNO ENAME      JOB              MGR HIREDATE                   SAL       COMM     DEPTNO
    ---------- ---------- --------- ---------- ------------------- ---------- ---------- ----------
          7876 ADAMS      CLERK           7788 1987/05/23 00:00:00       1100                    20
          7499 ALLEN      SALESMAN        7698 1981/02/20 00:00:00       1600        300         30
          7698 BLAKE      MANAGER         7839 1981/05/01 00:00:00       2850                    30
          7782 CLARK      MANAGER         7839 1981/06/09 00:00:00       2450                    10
          7902 FORD       ANALYST         7566 1981/12/03 00:00:00       3000                    20
          7900 JAMES      CLERK           7698 1981/12/03 00:00:00        950                    30
          7566 JONES      MANAGER         7839 1981/04/02 00:00:00       2975                    20
          7839 KING       PRESIDENT            1981/11/17 00:00:00       5000                    10
          7654 MARTIN     SALESMAN        7698 1981/09/28 00:00:00       1250       1400         30
          7934 MILLER     CLERK           7782 1982/01/23 00:00:00       1300                    10
          7788 SCOTT      ANALYST         7566 1987/04/19 00:00:00       3000                    20
          7369 SMITH      CLERK           7902 1980/12/17 00:00:00        800                    20
          7844 TURNER     SALESMAN        7698 1981/09/08 00:00:00       1500          0         30
          7521 WARD       SALESMAN        7698 1981/02/22 00:00:00       1250        500         30
    
    14 rows selected.
    
    SQL> select * from dev_emp order by ename;
    
         EMPNO ENAME      JOB              MGR HIREDATE                   SAL       COMM     DEPTNO
    ---------- ---------- --------- ---------- ------------------- ---------- ---------- ----------
            11 ADAMS      CLERK              8 1987/05/23 00:00:00       1100                    20
             2 ALLEN      SALESMAN           6 1981/02/20 00:00:00       1600        300         30
             6 BLAKE      MANAGER            9 1981/05/01 00:00:00       2850                    30
             7 CLARK      MANAGER            9 1981/06/09 00:00:00       2450                    10
            13 FORD       ANALYST            4 1981/12/03 00:00:00       3000                    20
            12 JAMES      CLERK              6 1981/12/03 00:00:00        950                    30
             4 JONES      MANAGER            9 1981/04/02 00:00:00       2975                    20
             9 KING       PRESIDENT            1981/11/17 00:00:00       5000                    10
             5 MARTIN     SALESMAN           6 1981/09/28 00:00:00       1250       1400         30
            14 MILLER     CLERK              7 1982/01/23 00:00:00       1300                    10
             8 SCOTT      ANALYST            4 1987/04/19 00:00:00       3000                    20
             1 SMITH      CLERK             13 1980/12/17 00:00:00        800                    20
            10 TURNER     SALESMAN           6 1981/09/08 00:00:00       1500          0         30
             3 WARD       SALESMAN           6 1981/02/22 00:00:00       1250        500         30
    
    14 rows selected.
    
    SQL>
    

    There are a number of variations on this approach that can be considered to be based on what must be hidden and volumes of data involved.

  • Multilingual in XMLTYPE problem

    Hi Experts,

    My database as follows:

    Oracle Database 11 g Enterprise Edition Release 11.2.0.3.0 - 64 bit Production

    PL/SQL Release 11.2.0.3.0 - Production

    CORE Production 11.2.0.3.0

    AMT for Linux: Version 11.2.0.3.0 - Production

    NLSRTL Version 11.2.0.3.0 - Production

    WE8ISO8859P1 NLS_CHARACTERSET

    IM XML storage in one of the table in my database in the XMLTYPE column. But when my XML node contains a multilingual value (Ex: Chinese) is to show the Junk value. Is it possible to store it's?

    INSERT IN web_xml_file (file_no, web_file_data, record_status, user_created, created) VALUES (v_file_no, xmltype.createxml (p_in_xml), "UNP", USER, SYSDATE);

    NUMBER FILE_NO,

    XMLTYPE OF the WEB_FILE_DATA,

    RECORD_STATUS VARCHAR2 (3),

    MSG_ERREUR VARCHAR2 (4000).

    USER_CREATED VARCHAR2 (50).

    DATE OF CREATION,

    USER_CHANGED VARCHAR2 (50).

    MODIFICATION DATE

    The following seems to work but be aware, that this is still a hack and certainly not bulletproof.

    The best way to handle this is to have the AL32UTF8 migrated db character set, or the external analysis.

    Select utl_i18n.raw_to_nchar (utl_i18n.string_to_raw (skywardsnumber), 'AL32UTF8') as skywardsnumber

    utl_i18n.raw_to_nchar (utl_i18n.string_to_raw (title), "AL32UTF8") as the title

    utl_i18n.raw_to_nchar (utl_i18n.string_to_raw (firstname), "AL32UTF8") as a first name

    utl_i18n.raw_to_nchar (utl_i18n.string_to_raw (familyname), "AL32UTF8") as familyname

    from xmltable ('/ data/passengerinformation ')

    from xmltype (dbms_xslprocessor.read2clob ('XML_DIR', 'multi.xml', nls_charset_id('CHAR_CS')))

    path of columns skywardsnumber varchar2 (100) 'skywardsnumber '.

    , title varchar2 (100) path 'title '.

    , path of varchar2 (100) firstname "firstname".

    , familyname varchar2 (100) path "familyname".

    ) x ;

    Explanations:

    (1) I put your example of XML in a file saved with UTF-8 encoding and it shipped to a database directory (DOC_DIR).

    (2) I have access to the file as CLOB using DBMS_XSLPROCESSOR.read2clob, and (here's the trick) considering the file in the db character set (mine was WE8ISO8859P15). Accordingly, all multibyte characters are converted into single-byte characters in the DB character set.

    (3) I use the XMLType constructor to construct an instance of XMLType off the CLOB and analyze with XMLTABLE.

    (4) who gives me four columns which I then convert into sequences of bytes (utl_i18n.string_to_raw) and finally to NCHAR (utl_i18n.raw_to_nchar) by specifying the encoding of the original file.

  • Issue in custom authentication

    Hi all

    I created a new custom authentication. The name of the function specified in the authentication scheme. My code seems to work very well (Boolean condition works) but authentication fails. Here's the package. Is there any other condition, I need the installation when you create to authenticate.

    can someone please suggest.


    create or replace package body app_login
    is
    Function get_hash(p_input IN varchar2)
    return varchar2
    is 
    begin
    
    RETURN UPPER(DBMS_OBFUSCATION_TOOLKIT.MD5 (
                     INPUT => UTL_I18N.STRING_TO_RAW(P_INPUT)));
                        -- return p_input;
    end get_hash;
    
    FUNCTION valid_user(p_username IN VARCHAR2 ,p_password IN VARCHAR2)
    return boolean
    is
    
    v_hash varchar2(200);
    V_RESULT number;
    v_pwd DEMO1_USER.PASSWORD%type;
    
    begin
    v_hash:=app_login.get_hash(P_USERNAME || P_PASSWORD);
    
    SELECT COUNT(*)
             INTO V_RESULT
              FROM DEMO1_USER
                WHERE UPPER(USERNAME) = UPPER(P_USERNAME)
                            AND UPPER(PASSWORD) = UPPER(V_HASH);
    
    
     IF V_RESULT > 0 THEN
           RETURN TRUE;
        ELSE
           RETURN FALSE;
        END IF;
    
    end valid_user;
    
    Procedure add_user(p_username IN VARCHAR2 ,p_password IN VARCHAR2)
    is 
    v_pwd_hash varchar2(200);
    begin
    v_pwd_hash:=app_login.get_hash(P_USERNAME || P_PASSWORD);
    insert into demo1_user values(APP_USER_SEQ.nextval,p_username,v_pwd_hash);
    commit;
    end add_user;
    
    
    
    end app_login;
     
    Thank you
    REDA

    Renon wrote:
    Hi Hari,

    Thank you very much for your time this issue. His works now.
    But the add_user function and the valid_user calls the function get_hash even without stem previously so why validation fails? Is required to be capitalized?

    Concerning
    REDA

    User name will always be in uppercase letters, regardless of how the user entered in the login screen. So in fact, UPPER (P_USERNAME) based on authentication valid_user is not necessary. However I have just kept it so that it returns the correct value when you run it go back. (for the objective test) etc.

    Value of variable binding that app_user will always be as HIGH of breakage.

    Kind regards
    Hari

  • How do I know the size specific to a field in an oracle table

    Hello

    Oracle 11.2.0.3 on redhat
    I have three tables with the same structure, table0, table50, table100:

    create table table0 (ID options, shipping RAW (2000), RAW (2000));

    I inserted some 10000 lines each, but with a few differences:
    Table0 a 10000 id, but shipping and options has null values
    table50 has 10000 id, but shipping and options has only 5000 lines, the other 5000 are null values
    table100 has 10000 lines of id, shipping and options. No null values.

    I want to know the specific size of each column, also the size of each line, namely the exactly size of the field.

    for example:

    rank 1, the column of table100 options is "asdfasdfagasdgasbabsdgoasdpgiahnwe1129u412094u12".
    rank 2, the table100 column options is "a".
    both are given in raw format, but I think that its space will be a different size (bytes), how do you know? any question?

    I found this query:
    select owner,tablespace_name,segment_name,sum((bytes/1024/1024)) Bytes
    from sys.dba_extents
    where owner in 'MAA' and segment_type='TABLE' and segment_name ='TABLE00'
    group by tablespace_name,owner,segment_name
    order by owner,tablespace_name,segment_name, bytes; 
    but I think that is not my solution.

    If VSIZE returns a constant value, which allows to conclude that everything which is inserting the data in your table is always inserting a constant number of bytes.

    If I create a table with a RAW (1000) and insert data with different sizes of binary, VSIZE gives different results

    SQL> create table foo(
      2    col1 raw(1000)
      3  );
    
    Table created.
    
    SQL> insert into foo values( utl_raw.cast_from_number(12) );
    
    1 row created.
    
    SQL> insert into foo values( utl_i18n.string_to_raw('This could be a much longer string') );
    
    1 row created.
    
    SQL> select vsize(col1) from foo;
    
    VSIZE(COL1)
    -----------
              2
             34
    

    If you say VSIZE always returns the value 1000, which implies that everything what is the insertion of the data is always inserting 1000 bytes of data.

    Justin

  • Encrypt/decrypt

    Hello
    in Oracle 10 g / 11g, is there a way to encrypt/decrypt the password?

    DBMS_CRYPTO is used for encryption and encryption.

    http://download.Oracle.com/docs/CD/E11882_01/AppDev.112/e25788/d_crypto.htm#i1005082

    Example of documentation:

    set serveroutput on
    DECLARE
       input_string       VARCHAR2 (200) :=  'Secret Message';
       output_string      VARCHAR2 (200);
       encrypted_raw      RAW (2000);             -- stores encrypted binary text
       decrypted_raw      RAW (2000);             -- stores decrypted binary text
       num_key_bytes      NUMBER := 256/8;        -- key length 256 bits (32 bytes)
       key_bytes_raw      RAW (32);               -- stores 256-bit encryption key
       encryption_type    PLS_INTEGER :=          -- total encryption type
                                DBMS_CRYPTO.ENCRYPT_AES256
                              + DBMS_CRYPTO.CHAIN_CBC
                              + DBMS_CRYPTO.PAD_PKCS5;
    BEGIN
       DBMS_OUTPUT.PUT_LINE ( 'Original string: ' || input_string);
       key_bytes_raw := DBMS_CRYPTO.RANDOMBYTES (num_key_bytes);
       encrypted_raw := DBMS_CRYPTO.ENCRYPT
          (
             src => UTL_I18N.STRING_TO_RAW (input_string,  'AL32UTF8'),
             typ => encryption_type,
             key => key_bytes_raw
          );
        -- The encrypted value "encrypted_raw" can be used here
        DBMS_OUTPUT.PUT_LINE ( 'Encrypted string: ' || encrypted_raw);
    
       decrypted_raw := DBMS_CRYPTO.DECRYPT
          (
             src => encrypted_raw,
             typ => encryption_type,
             key => key_bytes_raw
          );
       output_string := UTL_I18N.RAW_TO_CHAR (decrypted_raw, 'AL32UTF8');
    
       DBMS_OUTPUT.PUT_LINE ('Decrypted string: ' || output_string);
    END;
    /
    
    anonymous block completed
    
    Original string: Secret Message
    Encrypted string: D1C69EB14E5D335AC73D4F63E77C6D9D
    Decrypted string: Secret Message
    
  • DBMS_CRYPTO error display. Encrypt

    Dear all

    IAM using this procedure DBMS_CRYPTO. ENCRYPT)
    SRC = > UTL_I18N. STRING_TO_RAW (p_in_data, 'AL32UTF8'),
    Typ = > v_encryption_type,
    key = > v_key_bytes_raw,
    IV = > p_iv
    );

    and I have this problem

    package body "DBMS_CRYPTO" contains errors
    ORA-06508: PL/SQL: called program unit is not found: 'DBMS_CRYPTO.
    ORA-06512: at "ENCRYPTION", line 207
    ORA-06512: at line 1

    >
    package body "DBMS_CRYPTO" contains errors
    ORA-06508: PL/SQL: called program unit is not found: 'DBMS_CRYPTO.
    ORA-06512: at "ENCRYPTION", line 207
    ORA-06512: at line 1
    >

    You have no privilege to run the dbms_crypto package. Connect as sysdba and grant run access for this package for the respective user.

    Concerning

    REDA

  • java.sql.SQLException: ORA-06550 and ORA-00900 call stored procedures

    Hi all

    I have 2 a stored procedures that I want to call from my Session bean. One of them takes a few settings, but not the other. When I call the procedures, I get the following errors described below. I tested the two stored procedures in sql plus and sqldveleoper and they work well. The funniest, it is, I have another stored procedure that I can call successfully from the same bean in session with no problems, so I'm a bit confused as to why his play now.

    I use stand-alone 10.1.3.4 OC4J and Oracle 10 g Db 10.2.0.4 and platform DB that I use is Oracle10gPlatform and Eclipselink as my JPA provider. I have also tried against toplink (not toplink essentials) and still no joy

    Here is the error I get when I try and call the procedure which takes the parameters of the session bean
    Internal Exception: java.sql.SQLException: ORA-06550: line 1, column 7:
    PLS-00306: wrong number or types of arguments in call to 'HASHDATA'
    ORA-06550: line 1, column 7:
    PL/SQL: Statement ignored
    
    Error Code: 6550
    Call: BEGIN HashData(input=>?, hashedValue=>?, hashed=>?); END;
         bind => [password1, => hashedValue, => hashed]
    Query: DataReadQuery()
    Here are my stored procedure that take parameters
    create or replace procedure hashData(input IN VARCHAR2, hashedValue OUT BLOB, hashed OUT BOOLEAN)  as  
    
    inputRaw RAW(2000);
    --hashed BOOLEAN := false;
    begin 
    
    dbms_output.put_line('the data to be hashed is '||input);
    
    dbms_output.put_line('converting input to raw ...');
    inputRaw := utl_i18n.string_to_raw(input,'AL32UTF8');
    
    dbms_output.put_line('Hashing Data ...');
    hashedValue := DBMS_CRYPTO.Hash (src=>inputRaw,typ=>DBMS_CRYPTO.HASH_SH1);
    
    dbms_output.put_line('hash is '||UTL_I18N.raw_to_char(dbms_lob.substr(hashedValue, 4000,1)));
    
    if (hashedValue  is not null) then 
     
    
     hashed :=true;
      dbms_output.put_line('hashedValue IS NOT  null');
     else
     hashed := false;
      dbms_output.put_line('hashedValue IS null');
     end if;
    
    end;
    Here is my code in the session bean to call the procedure that takes as parameters (Hashdata)

    public UserBean() {
              // TODO Auto-generated constructor stub
    
              sessMan = SessionManager.getManager();
              session = sessMan.getSession("Session", Thread.currentThread()
                        .getContextClassLoader());
    
         }
    
    public Serializable hashData(String input){
    
              logger.debug("Hashing Data ... "); 
              hashedValue= null; 
              boolean hashed=false; 
         
              StoredProcedureCall call = new StoredProcedureCall();
    
              ValueReadQuery query = new ValueReadQuery();
              call.setProcedureName("HashData");
              call.addNamedArgumentValue("input", input);
              call.addNamedOutputArgument("hashedValue", "hashedValue", java.sql.Blob.class);
              call.addNamedOutputArgument("hashed", "hashed", java.lang.Integer.class);
                        
              query.addArgument("input");
              
              query.setCall(call);
              
              session.executeQuery(query);
               
              if ((Boolean)hashed){
                   logger.debug("The data has been hashed and the hash value is: "+hashedValue);
              }
              
              else{
                   logger.debug("The data has could not be hashed");
                   hashedValue=null;
              }
              
              return (Serializable)hashedValue;
              }
    When I call the other takes no parameters, I get the following error.
    Internal Exception: java.sql.SQLException: ORA-00900: invalid SQL statement
    
    Error Code: 900
    Call: BEGIN testJPAProc(); END;
    Query: DataReadQuery()
    Here is the procedure which takes no parameters
    create or replace procedure testJPAProc is 
     
     begin
     dbms_output.put_line('testJPAProc called');
     end;
    Heres is the code to call procedures that take no parameters
                                    StoredProcedureCall call = new StoredProcedureCall();
      
              ValueReadQuery query = new ValueReadQuery();
              
              call.setProcedureName("testJPAProc");
              query.setCall(call);
              
              session.executeQuery(query);
    You guys can tell me where I'm wrong if I do something wrong. Why make these mistakes? because as far as I can tell the code (java and pl/sql) are both correct unless there is something I missed. It's kinda funny because I have another stored procedure I can call successfully.


    Thank you

    The first question is that the Boolean in Oracle is not a supported JDBC type, but a PLSQL type.
    Change to an INTEGER is probably the best, you can also use the PLSQLStoredProcedureCall class to access.

    The second problem is perhaps that the stored procedure is not valid, make sure that it compiled correctly. It can also be the type of your query, you must use a DataModifyQuery, not a read request that it returns nothing.
    If still no luck, try to call directly through JDBC, it works?

    ---
    James: http://www.eclipselink.org: http://en.wikibooks.org/wiki/Java_Persistence

  • Oracle password algorithm

    Hi I'm trying to simulate oracle algorithm to create a hash of the user name and password.

    the version of the database is 10.2

    >
    Algorithm:
    1 concatenate the user name and the password to produce a string of plain text;
    2 convert the string in clear uppercase;
    3 convert the string of plain text to the storage format of number of bytes; ASCII characters have the
    high byte value 0 x 00;
    4 encrypt the plain text string (completed with 0 if necessary for the next block length)
    using the algorithm in block cipher block chaining) the CBC mode (with a fixed key value of)
    0x0123456789ABCDEF;
    5. encrypt the string of plaintext with DES-CBC, but using the last output block
    from the previous step (without taking into account the parity bits) as the encryption key. The last block of the
    output is converted to a printable string in order to get the password hash value.
    >
    DECLARE
      username varchar2(30):= 'bob';
      pass varchar2(30):='bob1';
         enc_val RAW(2048);
      str varchar2(60);
      l_mod number;
      key_bytes      RAW (16):=hextoraw('0123456789ABCDEF');
    BEGIN
      str:= UPPER(username || pass);
    
      l_mod:= dbms_crypto.ENCRYPT_DES + dbms_crypto.CHAIN_CBC+ dbms_crypto.PAD_ZERO;
      
      enc_val := dbms_crypto.encrypt(UTL_I18N.STRING_TO_RAW (str,  'AL32UTF8'),l_mod,key_bytes);
      enc_val := dbms_crypto.encrypt(UTL_I18N.STRING_TO_RAW (str,  'AL32UTF8'),l_mod, enc_val);
         
      dbms_output.put_line(enc_val);
    END;
    I got:
    A338AB13B60756EA
    And if I try:
    Select password from sys.user$ where name = "BOB";
    D5D3AA09DD03B20F

    What I am doing wrong?

    Take the unicode_str functions and crack of his screenplay.

Maybe you are looking for