Solved

Encode and decode in Oracle

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

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.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Can't Access My Database 57 76
constraint check 2 48
error in my cursor 5 41
oracle date format checking 7 26
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…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
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.
This video shows how to configure and send email from and Oracle database using both UTL_SMTP and UTL_MAIL, as well as comparing UTL_SMTP to a manual SMTP conversation with a mail server.

839 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