Solved

Encode and decode in Oracle

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

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

Question has a verified solution.

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

How to Unravel a Tricky Query Introduction If you browse through the Oracle zones or any of the other database-related zones you'll come across some complicated solutions and sometimes you'll just have to wonder how anyone came up with them.  …
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…
This video explains at a high level about the four available data types in Oracle and how dates can be manipulated by the user to get data into and out of the database.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Suggested Courses

617 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