[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Encrypt and Decrypt with DES3Encrypt Oracle

Posted on 2003-11-05
3
Medium Priority
?
1,791 Views
Last Modified: 2007-12-19
Hi
I have a function

create or replace function endecrypt_fnc(
  inValue  varchar2,  --Value to en/decrypt
  inMethod varchar2  --'E' Encrypt; 'D' Decrypt
) return varchar2
is
  loResult         varchar2(4096) ;
  loKey            VARCHAR2(24) := 'QWERTYUIASDFGHJKZXCVBNM,';
  lovalue          VARCHAR2(4096) ;
  loMethod         varchar2(1);
  error_in_input_buffer_length EXCEPTION;
  PRAGMA EXCEPTION_INIT(error_in_input_buffer_length, -28232);
  INPUT_BUFFER_LENGTH_ERR_MSG VARCHAR2(100) := '*** DES INPUT BUFFER NOT A MULTIPLE OF 8 BYTES ***';
  i number;
BEGIN
  if inValue is null then
    return null;
  end if;
  loValue := inValue;
  loMethod := upper(inMethod);
  if loMethod='E' THEN
    loResult :=  dbms_obfuscation_toolkit.DES3Encrypt(
       input_string => loValue,
       key_string => loKey,
       which => 1);
  end if;
  if loMethod='D' THEN
    loResult :=  dbms_obfuscation_toolkit.DES3Decrypt(
       input_string => loValue,
       key_string => loKey,
       which => 1);
  end if;
  return loResult;

EXCEPTION
WHEN error_in_input_buffer_length THEN
  dbms_output.put_line('> ' || INPUT_BUFFER_LENGTH_ERR_MSG);

end endecrypt_fnc;

I tested with some values below:
  endecrypt_fnc(endecrypt_fnc('12345678','E'),'D') it's ok
but when i tested
  endecrypt_fnc(endecrypt_fnc('913122875       ','E'),'D') the return value does not match.

---length('913122875       ')=16----

Let me know what something wrong, pls?
Thanks
HieuTD
0
Comment
Question by:hieutd
1 Comment
 
LVL 23

Accepted Solution

by:
seazodiac earned 1000 total points
ID: 9688046
try to use a longer key 32 bytes.
---> loKey            VARCHAR2(24) := 'QWERTYUIASDFGHJKZXCVBNM,';
loKey            VARCHAR2(24) := 'IDLSFDKLQWERTYUIASDFGHJKZXCVBNM,';
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this series, we will discuss common questions received as a database Solutions Engineer at Percona. In this role, we speak with a wide array of MySQL and MongoDB users responsible for both extremely large and complex environments to smaller singl…
In this article, we’ll look at how to deploy ProxySQL.
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question