Oracle Cryptographic Toolkit Programmer's Guide
Release 2.0.4

A54082-02

Library

Product

Contents

Index

Prev Next

A
Sample PL/SQL Code

This appendix contains a sample PL/SQL program written in C.

A.1 Sample PL/SQL Program

Following is a sample PL/SQL program for your reference. Segments of this code are numbered and contain narrative text explaining portions of the code.

declare

wallet dbms_crypto_toolkit.Wallet;
persona_list dbms_crypto_toolkit.Persona_List;
persona dbms_crypto_toolkit.Persona;
string_input VARCHAR2(6)  := `123456';
signature RAW(2048);
signing_party dbms_crypto_toolkit.Identity;
recipient dbms_crypto_toolkit.Identity;
-- Flags to indicate the package state.
initialized BOOLEAN := FALSE;
wallet_opened BOOLEAN := FALSE;
persona_opened BOOLEAN := FALSE;
operation_unsupported EXCEPTION;
PRAGMA EXCEPTION_INIT (operation_unsupported, -28841);
ENCRYPTION_UNSUPPORTED_MESSAGE VARCHAR2(64) :=
 `**** ENCRYPTION UNSUPPORTED - IGNORING EXCEPTION ****';
encrypted_string VARCHAR2 (2048);
decrypted_string VARCHAR2 (2048);
extracted_string VARCHAR2 (128);
hash_string      VARCHAR2 (2048);
string_verified  BOOLEAN := FALSE;
string_validated BOOLEAN := FALSE;
all_done         BOOLEAN := FALSE;
done_exception   EXCEPTION;
BEGIN
  1. Start Oracle Cryptographic Toolkit operation.
    dbms_output.put_line(`> Initialize');
    dbms_crypto_toolkit.Initialize;
    initialized := TRUE;
    

  1. Open a wallet at the default location.
    dbms_output.put_line(`> OpenWallet');
    dbms_crypto_toolkit.OpenWallet(`server1', wallet, persona_list, `default:');
    wallet_opened := TRUE;
    

  1. Establish the identity associated with the first persona in the new wallet as the recipient.
    dbms_output.put_line(`>Alias ` || persona_list(1).alias);
    dbms_output.put_line(`>Comment ` || persona_list(1).comment);
    persona.persona := persona_list(1).persona;
    recipient.Descriptor := persona_list(1).identity;
    

  1. Open the first persona.
    dbms_output.put_line(`> OpenPersona');
    dbms_crypto_toolkit.OpenPersona(persona);
    persona_opened := TRUE;
    

  1. Create an attached signature associated with the current persona.
    dbms_output.put_line(`> Sign');
    dbms_crypto_toolkit.Sign(persona => persona, input => string_input, 
    signature => signature);

  1. Verify the attached signature.
    dbms_output.put_line(`> Verify');
    dbms_crypto_toolkit.Verify(persona => persona,
    
                              signature => signature,
                              extracted_message => extracted_string,
                              verified => string_verified,
                              validated => string_validated,
                              signing_pary_identity => signing_party);


IF string_validated THEN

dbms_output.put_line(`> Validated');
END IF; IF string_verified THEN
dbms_output.put_line(`> Verified');
END IF;
  1. Create a detached signature associated with the current persona.
    dbms_output.put_line(`> Sign detached');
    dbms_crypt_toolkit.SignDetached(persona => persona,
                                   input => string_input,
                                   signature => signature);

  1. Verify the detached signature.
    dbms_output.put_line(`> Verify detached');
    dbms_crypto_toolkit.VerifyDetached(persona => persona,
                                     data => string_input,
                                     signature => signature,
                                     verified => string_verified,
                                     validated => string_validated,
                                     signing_party_identity => signing_party);
    


IF string_validated THEN

dbms_output.put_line(`> Validated');
END IF; IF string_verified THEN
dbms_output.put_line(`> Verified');
END IF;
  1. Generate a hash of the current message.
    dbms_output.put_line(`> Hash');
    dbms_crypto_toolkit.Hash(persona => persona,
    
                            input => string_input,
                            hash => hash_string);


IF string_input = hash_string THEN

dbms_output.put_line(`> Hash Succeeded');
END IF;
all_done := TRUE RAISE done_exception; EXCEPTION WHEN others THEN
  1. Close the current open persona.
    IF persona_opened THEN
       dbms_output.put_line(`>ClosePersona.ClosePersona');
       dbms_crypto_toolkit.ClosePersona(persona);
    END IF;



BEGIN
  1. Close the current open persona.
    IF persona_opened THEN
    
    
    dbms_output.put_line(`> ClosePersona');
    dbms_crypto_toolkit.ClosePersona(persona);
    
    END IF;

  1. Close the open wallet.
    IF wallet_opened THEN
    
    
    dbms_output.put_line(`> CloseWallet');
    dbms_crypto_toolkit.CloseWallet(wallet);
    
    END IF;

  1. Stop the Oracle Cryptographic Toolkit operation.
    IF initialized THEN
    
    
    dbms_output.put_line(`> Terminate');
    dbms_crypto_toolkit.TERMINATE;
    
    END IF; IF all_done = FALSE THEN
    RAISE;
    
END;




Prev

Next
Oracle
Copyright © 1997 Oracle Corporation.

All Rights Reserved.

Library

Product

Contents

Index