Example of Oracle encryption/perl decryption with 3DES?

[email protected] ("Kyle Poquette") Mon, 22 Oct 2001 21:59:29
Newsgroups perl.crypto
Message-ID <[email protected]>
Hello. I am wondering if anyone on this list has a sample of code which 
encrypts data using 3DES with the Oracle DBMS_OBFUSCATION_TOOLKIT PL/SQL 
package in Oracle and decrypts it using the perl Crypt::TripleDES module in 
perl. I have been playing with this for a while and I am unable to get it to 
work or even find simple examples of how perl and Oracle should interact.

I am using Oracle version 8.1.7.2.0 and perl 5.00404 on Solaris. Below is 
the Oracle and perl code that I have created as a test. Does anyone know 
where I am going wrong?

Any help is greatly appreciated! Thanks! -Kyle
-----------------------------------------------------------------
ORACLE PL/SQL CODE
-- Create a test table ENCRYPTION_TABLE to hold encrypted value
CREATE TABLE encryption_table (
  encrypted_column RAW(1024)
);

-- Encrypt data and insert into ENCRYPTION_TABLE.ENCRYPTED_COLUMN
declare
  passphrase RAW(128) := UTL_RAW.CAST_TO_RAW('abcdefghijklmnop');
  plaintext RAW(128) := UTL_RAW.CAST_TO_RAW('abcdefghijklmnop');
  cyphertext RAW(1024);
begin
  cyphertext := DBMS_OBFUSCATION_TOOLKIT.DES3Encrypt(input => plaintext, key 
=> passphrase);
  INSERT INTO encryption_table
  VALUES
  (cyphertext);
end;
/
----------------------------------------------------------------
PERL CODE
#!/usr/local/bin/perl

use DBI;
use Crypt::TripleDES;
my $des = new Crypt::TripleDES;

# Set encryption values
my $passphrase = 'abcdefghijklmnop';
my $cyphertext;

# Set DBTS database values.
my $instance_sid = 'INSTANCE';
my $instance_username = 'user';
my $instance_password = 'password';

# Log on to the DBTS database and get basic database info.
$dbh = DBI->connect("dbi:Oracle:${instance_sid}", $instance_username,
                    $instance_password);

my $sql = "
   SELECT encrypted_column
     FROM encryption_table
";
$sth = $dbh->prepare($sql);
$sth->execute;
while (($encrypted_column) = $sth->fetchrow) {
  print $des->decrypt3($encrypted_column, $passphrase), "\n";
  print "\n";
}
$sth->finish;
$dbh->disconnect;

exit(0);




_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp