Solved

Encrypt and Decrypt with DES3Encrypt Oracle

Posted on 2003-11-05
3
1,696 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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

This article describes some very basic things about SQL Server filegroups.
These days, all we hear about hacktivists took down so and so websites and retrieved thousands of user’s data. One of the techniques to get unauthorized access to database is by performing SQL injection. This article is quite lengthy which gives bas…
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…

895 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

19 Experts available now in Live!

Get 1:1 Help Now