Skip to Content
Oracle PL/SQL for DBAs
book

Oracle PL/SQL for DBAs

by Arup Nanda, Steven Feuerstein
October 2005
Intermediate to advanced
454 pages
14h 44m
English
O'Reilly Media, Inc.
Content preview from Oracle PL/SQL for DBAs

Putting It Together

Now that you’ve learned about the components of the encryption process, let’s put it all together to build our own unified tool. I’ll modify our old faithful get_enc_val function as follows.

    /* File on web: get_enc_val_5.sql */

    CREATE OR REPLACE FUNCTION get_enc_val (
       p_in_val   IN   VARCHAR2,
       p_key      IN   VARCHAR2,
       p_iv       IN   VARCHAR2 := NULL,
       p_which    IN   NUMBER := 0
    )
       RETURN VARCHAR2
    IS
       l_enc_val   VARCHAR2 (200);
       l_in_val    VARCHAR2 (200);
       l_iv        VARCHAR2 (200);
    BEGIN
       IF p_which = 0
       THEN
          IF LENGTH (p_key) < 16
          THEN
             raise_application_error
                                   (-20001,
                                    'Key length less than 16 for two-pass scheme'
                                   );

          END IF;
       ELSIF p_which = 1
       THEN
          IF LENGTH (p_key) < 24
          THEN
             raise_application_error
                                 (-20002,
                                  'Key length less than 24 for three-pass scheme'
                                 );
          END IF;
       ELSE
          raise_application_error (-20003,
                                      'Incorrect value of which '
                                   || p_which
                                   || '; must be 0 or 1'
                                  );
       END IF;

       l_in_val := RPAD (p_in_val, (8 * ROUND (LENGTH (p_in_val) / 8, 0) + 8));
       l_iv := RPAD (p_iv, (8 * ROUND (LENGTH (p_iv) / 8, 0) + 8));
       l_enc_val :=
          DBMS_OBFUSCATION_TOOLKIT.des3encrypt (input_string      => l_in_val,
                                                key_string        => p_key,
                                                iv_string         => l_iv,
                                                which             => p_which
                                               );
       l_enc_val := RAWTOHEX (UTL_RAW.cast_to_raw (l_enc_val));
       RETURN l_enc_val;
    END;
    /

I’ll also build a similar function for decryption, named get_dec_val, as follows.

 /* File on web: get_dec_val_1.sql */ CREATE OR REPLACE FUNCTION get_dec_val ( p_in_val VARCHAR2, p_key VARCHAR2, p_iv VARCHAR2 := NULL, p_which NUMBER := 0 ) RETURN VARCHAR2 IS l_dec_val VARCHAR2 (2000); ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Oracle PL/SQL Best Practices

Oracle PL/SQL Best Practices

Steven Feuerstein
Resilient Oracle PL/SQL

Resilient Oracle PL/SQL

Stephen B. Morris
Expert Oracle PL/SQL

Expert Oracle PL/SQL

Ron Hardman, Michael McLaughlin

Publisher Resources

ISBN: 0596005873Errata Page