Home » SQL & PL/SQL » SQL & PL/SQL » Converting text to ascii and vice versa at application level (Oracle 9i, Developer 2000)
Converting text to ascii and vice versa at application level [message #347817] Sun, 14 September 2008 05:06 Go to next message
x_silent_freak_x
Messages: 5
Registered: September 2008
Location: Kuwait
Junior Member

hello my oracle brethen...
i need to create a table in the database with one column (say credit card number) as encrypted...
however it should be accessible at the application level...
so i figured that id have a function/procedure that converts that field at form level and then saves in encrypted form in the database...
so that way it would look like a string of random numbers in the table...
i searched online but couldnt come across any codes for converting a string to ascii...
so basically yeah... thats what im looking for...
any help with converting a string to ascii and vice versa...
thanks...
Re: Converting text to ascii and vice versa at application level [message #347819 is a reply to message #347817] Sun, 14 September 2008 05:57 Go to previous messageGo to next message
Littlefoot
Messages: 21823
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
Perhaps DBMS_OBFUSCATION_TOOLKIT is what you are looking for.
Re: Converting text to ascii and vice versa at application level [message #347820 is a reply to message #347817] Sun, 14 September 2008 06:02 Go to previous messageGo to next message
x_silent_freak_x
Messages: 5
Registered: September 2008
Location: Kuwait
Junior Member

I checked that out some days back but im just looking for a procedure/function that converts a string to ascii and vice versa...
would appreciate it if u have any such code...
thanks again...
Re: Converting text to ascii and vice versa at application level [message #347823 is a reply to message #347820] Sun, 14 September 2008 06:14 Go to previous messageGo to next message
Littlefoot
Messages: 21823
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
But, that's quite a poor encryption; functions that do the job are ASCII and CHR:
SQL> select ascii(2) from dual;

  ASCII(2)
----------
        50

SQL> select chr(50) from dual;

C
-
2

SQL>
You could create your own function if you wish, playing around with these Oracle functions, but ... hm.
Re: Converting text to ascii and vice versa at application level [message #347826 is a reply to message #347817] Sun, 14 September 2008 06:26 Go to previous messageGo to next message
x_silent_freak_x
Messages: 5
Registered: September 2008
Location: Kuwait
Junior Member

lol... i know this already...
SQL> select ascii('blah') from dual
  2  /

ASCII('BLAH')
-------------
           98

SQL> select chr(98) from dual
  2  /

C
-
b

i did this in a for loop too to check each character but it still doesnt do the job...
hmmmm...
or maybe my for loop thing was wrong... hmmmm...
Re: Converting text to ascii and vice versa at application level [message #348001 is a reply to message #347826] Mon, 15 September 2008 06:18 Go to previous messageGo to next message
JRowbottom
Messages: 5933
Registered: June 2006
Location: Sunny North Yorkshire, ho...
Senior Member
If you're going to encrypt something, do it properly, or not at all.
Poorly encrypted data gives you only the illusion of security.
Re: Converting text to ascii and vice versa at application level [message #348008 is a reply to message #347817] Mon, 15 September 2008 06:56 Go to previous messageGo to next message
x_silent_freak_x
Messages: 5
Registered: September 2008
Location: Kuwait
Junior Member

hmmm...
what do u suggest?!?!...
Re: Converting text to ascii and vice versa at application level [message #348011 is a reply to message #348008] Mon, 15 September 2008 06:59 Go to previous messageGo to next message
Michel Cadot
Messages: 68733
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator
Littlefoot wrote on Sun, 14 September 2008 12:57
Perhaps DBMS_OBFUSCATION_TOOLKIT is what you are looking for.

Re: Converting text to ascii and vice versa at application level [message #348601 is a reply to message #347817] Wed, 17 September 2008 06:54 Go to previous messageGo to next message
x_silent_freak_x
Messages: 5
Registered: September 2008
Location: Kuwait
Junior Member

after some major googling... i came across this...
i modified it to serve my purpose and it does what i was looking for...

CREATE OR REPLACE PACKAGE Cryptit AS
   FUNCTION encrypt( Str VARCHAR2 ) RETURN RAW;
   FUNCTION decrypt( xCrypt VARCHAR2 ) RETURN VARCHAR2;
END Cryptit;
/

CREATE OR REPLACE PACKAGE BODY Cryptit AS
   crypt_raw RAW(2000);
   crypt_str VARCHAR(2000);

   -- Encrypt the string --
   FUNCTION encrypt( Str VARCHAR2 ) RETURN RAW AS

   l INTEGER := LENGTH(str);
   i INTEGER;
   padblock RAW(2000);
   Cle RAW(8) := UTL_RAW.CAST_TO_RAW('frankzap');

   BEGIN
      i := 8-MOD(l,8);
      padblock := utl_raw.cast_to_raw(str||RPAD(CHR(i),i,CHR(i)));

      dbms_obfuscation_toolkit.DESEncrypt(
               input     => padblock,
               KEY       => Cle,
               encrypted_data => crypt_raw );
      RETURN crypt_raw ;
   END;

   -- Decrypt the string --
   FUNCTION decrypt( xCrypt VARCHAR2 ) RETURN VARCHAR2 AS
   l NUMBER;
   Cle RAW(8) := UTL_RAW.CAST_TO_RAW('frankzap');
   crypt_raw RAW(2000) := utl_raw.cast_to_raw(utl_raw.cast_to_varchar2(xCrypt)) ;
   BEGIN
      dbms_obfuscation_toolkit.DESDecrypt(
               input     => xCrypt,
               KEY       => Cle,
               decrypted_data => crypt_raw );
      crypt_str := utl_raw.cast_to_varchar2(crypt_raw);
      l := LENGTH(crypt_str);
      crypt_str := RPAD(crypt_str,l-ASCII(SUBSTR(crypt_str,l)));
      RETURN crypt_str;
   END;
END Cryptit;
/

SQL> DECLARE
  2    LC$Code VARCHAR2(100) := 'Music is the best!' ;
  3  BEGIN
  4  
  5    -- Get the encrypted string --
  6    LC$Code := Cryptit.Encrypt( LC$Code ) ;
  7    dbms_output.put_line( LC$Code ) ;
  8  
  9    -- Get the decrypted string --
 10    LC$Code := Cryptit.Decrypt( LC$Code ) ;
 11    dbms_output.put_line( LC$Code ) ;
 12  
 13  END ;   
 14  
 15  /
7840712517939382157F5BA660E3AAB094E9C2BA67FF4234
Music is the best!


thanks again for the dbms_obfuscation_toolkit suggestion as opposed to my initial ascii - text conversion thing...
Re: Converting text to ascii and vice versa at application level [message #348612 is a reply to message #348601] Wed, 17 September 2008 07:28 Go to previous message
Michel Cadot
Messages: 68733
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator
Instead of posting the code you found you should post the link to the origin.

T. Kyte posted several examples, for instance:
http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:685421699413

Regards
Michel
Previous Topic: Query using joins
Next Topic: Help
Goto Forum:
  


Current Time: Thu Feb 06 14:21:45 CST 2025