Solved

Encode and decode in Oracle

Posted on 2000-04-03
4
3,586 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
  • 2
4 Comments
 
LVL 1

Accepted Solution

by:
mjkrijgsman earned 50 total points
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks for your information
M
0
 

Author Comment

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

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

Suggested Solutions

Note: this article covers simple compression. Oracle introduced in version 11g release 2 a new feature called Advanced Compression which is not covered here. General principle of Oracle compression Oracle compression is a way of reducing the d…
Introduction A previously published article on Experts Exchange ("Joins in Oracle", http://www.experts-exchange.com/Database/Oracle/A_8249-Joins-in-Oracle.html) makes a statement about "Oracle proprietary" joins and mixes the join syntax with gen…
This video shows how to copy a database user from one database to another user DBMS_METADATA.  It also shows how to copy a user's permissions and discusses password hash differences between Oracle 10g and 11g.
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…

771 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

10 Experts available now in Live!

Get 1:1 Help Now