Solved

Encode and decode in Oracle

Posted on 2000-04-03
4
3,608 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 50 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Background In several of the companies I have worked for, I noticed that corporate reporting is off loaded from the production database and done mainly on a clone database which needs to be kept up to date daily by various means, be it a logical…
From implementing a password expiration date, to datatype conversions and file export options, these are some useful settings I've found in Jasper Server.
This video shows setup options and the basic steps and syntax for duplicating (cloning) a database from one instance to another. Examples are given for duplicating to the same machine and to different machines
This video shows syntax for various backup options while discussing how the different basic backup types work.  It explains how to take full backups, incremental level 0 backups, incremental level 1 backups in both differential and cumulative mode a…

735 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