Solved

Encrypt and Decrypt with DES3Encrypt Oracle

Posted on 2003-11-05
3
1,680 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
3 Comments
 
LVL 23

Accepted Solution

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

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
SQL Command Tool comes with APEX under SQL Workshop. It helps us to make changes on the database directly using a graphical user interface. This helps us writing any SQL/ PLSQL queries and execute it on the database and we can create any database ob…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

706 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now