Solved

Encrypt and Decrypt with DES3Encrypt Oracle

Posted on 2003-11-05
3
1,755 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Webinar: MongoDB® Index Types

Join Percona’s Senior Technical Services Engineer, Adamo Tonete as he presents “MongoDB Index Types, How, When and Where Should They be Used?” on Wednesday, July 12, 2017 at 11:00 am PDT / 2:00 pm EDT (UTC-7).

Question has a verified solution.

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

Read about achieving the basic levels of HRIS security in the workplace.
Recently I was talking with Tim Sharp, one of my colleagues from our Technical Account Manager team about MongoDB’s scalability. While doing some quick training with some of the Percona team, Tim brought something to my attention...
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…
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…

717 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