Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Encode and decode in Oracle

Posted on 2000-04-03
4
Medium Priority
?
3,659 Views
Last Modified: 2008-02-26
Hi all
is there any way to encode and decode my data when write in and read out that use existing function/procedure in side oracle, or some ways else ???
Thanks
Minh
0
Comment
Question by:minhnv
[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
  • 2
4 Comments
 
LVL 1

Accepted Solution

by:
mjkrijgsman earned 100 total points
ID: 2680797
minhny,

Oracle 8.1.6 (aka Oracle8i release 2) has such a feature, stored data encryption. This functionality is offered by means of a PL/SQL package.
The encryption/decryption uses the industry-standard Data Encryption Standard (DES).

If you have an older version and no upgrade in sight, you probably have to look for algorithms from Internet. I can't help you with that.

Succes,

Marcel-Jan Krijgsman
Origin Nederland
0
 
LVL 1

Expert Comment

by:whbram
ID: 2682393
Try this code

encrypted_string := Encrypt_Decrypt('string');

I use this to encrypt passwords up to 30 chars in length


/*
*************************************************************************
**  NAME
**    Convert_Binary
**
**  DESCRIPTION
**    This function converts a character value to a binary value
**
**  ARGUMENTS
**    psCharVal - Character value
**
**  RETURNED
**    Converted binary value
**
*************************************************************************
*/

FUNCTION Convert_Binary( psCharVal varchar2 )
  RETURN varchar2 IS
 
  nLoop1  number;  
  nDivis  number := 128;
  nValue  number := Ascii( psCharVal );  

  /* Converted binary string */
  sResult varchar2(30) := '';  
 
BEGIN  

  FOR nLoop1 IN 0..29 LOOP  

    /* Determine Bit values */
    IF Trunc( nValue / nDivis ) = 1 THEN
      sResult := sResult || '1';
    ELSE
      sResult := sResult || '0';
    END IF;

    nValue := nValue Mod nDivis;  
    nDivis := nDivis / 2;  
  END LOOP;  

  /* Return converted string */
  RETURN( sResult );  

END Convert_Binary;  

/*
*************************************************************************
**  NAME
**    Encrypt_Decrypt
**
**  DESCRIPTION
**    This function encrypts/decrypts a string
**
**  ARGUMENTS
**    psString - String to encrypt or decrypt
**
**  RETURNED
**    Encrypted or Decrypted string
**
*************************************************************************
*/
  FUNCTION Encrypt_Decrypt( psString varchar2 )
    RETURN varchar2 IS  

    nLoop1 number;
    nloop2 number;
    nDivis number;  

    /* Temporary variables */
    sTemp1 varchar2(30);
    sTemp2 varchar2(30);
    nTemp3 number;

    /* Seed string */
    sSeedStr varchar2(30) := '!@#$%^&*()!@#$%^&*()!@#$%^&*()';

    /* Converted string */
    sConvStr varchar2(30) := '';  

  BEGIN

    FOR nLoop1 IN 1..NVL( Length( psString ), 0 ) LOOP
      sTemp1 := Convert_Binary( Substr( psString, nLoop1, 1 ) );  
      sTemp2 := Convert_Binary( Substr( sSeedStr, nLoop1, 1 ) );  
      nTemp3 := 0;
      nDivis := 128;

      FOR nLoop2 IN 1..30 LOOP  
        IF ( To_Number( SubStr( sTemp1, nLoop2, 1 ) ) +
             To_Number( Substr( sTemp2, nLoop2, 1 ) ) ) = 1 THEN
          nTemp3 := nTemp3 + nDivis;
        END IF;  

        nDivis := nDivis / 2;  
      END LOOP;  

      sConvStr := sConvStr || Chr( nTemp3 );  
    END LOOP;

    /* Return encrypted/decrypted string */
    RETURN( sConvStr );  

  END Encrypt_Decrypt;
0
 

Author Comment

by:minhnv
ID: 2686071
Thanks for your information
M
0
 

Author Comment

by:minhnv
ID: 2686123
Thanks for Whbram algorithm, a smart way of solution !!!
M
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

Why doesn't the Oracle optimizer use my index? Querying too much data Most Oracle developers know that an index is useful when you can use it to restrict your result set to a small number of the total rows in a table. So, the obvious side…
This post first appeared at Oracleinaction  (http://oracleinaction.com/undo-and-redo-in-oracle/)by Anju Garg (Myself). I  will demonstrate that undo for DML’s is stored both in undo tablespace and online redo logs. Then, we will analyze the reaso…
Via a live example show how to connect to RMAN, make basic configuration settings changes and then take a backup of a demo database
This video shows information on the Oracle Data Dictionary, starting with the Oracle documentation, explaining the different types of Data Dictionary views available by group and permissions as well as giving examples on how to retrieve data from th…

688 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