Oracle Cryptographic Toolkit Programmer's Guide Release 2.0.4 A54082-02 |
|
This appendix contains a sample PL/SQL program written in C.
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.
declarewallet 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
dbms_output.put_line(`> Initialize'); dbms_crypto_toolkit.Initialize; initialized := TRUE;
dbms_output.put_line(`> OpenWallet'); dbms_crypto_toolkit.OpenWallet(`server1', wallet, persona_list, `default:'); wallet_opened := TRUE;
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;
dbms_output.put_line(`> OpenPersona'); dbms_crypto_toolkit.OpenPersona(persona); persona_opened := TRUE;
dbms_output.put_line(`> Sign'); dbms_crypto_toolkit.Sign(persona => persona, input => string_input,
signature => 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 THENdbms_output.put_line(`> Validated');END IF; IF string_verified THENdbms_output.put_line(`> Verified');END IF;
dbms_output.put_line(`> Sign detached'); dbms_crypt_toolkit.SignDetached(persona => persona, input => string_input, signature => 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 THENdbms_output.put_line(`> Validated');END IF; IF string_verified THENdbms_output.put_line(`> Verified');END IF;
dbms_output.put_line(`> Hash'); dbms_crypto_toolkit.Hash(persona => persona,
input => string_input, hash => hash_string);IF string_input = hash_string THENall_done := TRUE RAISE done_exception; EXCEPTION WHEN others THENdbms_output.put_line(`> Hash Succeeded');END IF;
IF persona_opened THEN dbms_output.put_line(`>ClosePersona.ClosePersona'); dbms_crypto_toolkit.ClosePersona(persona); END IF;BEGIN
IF persona_opened THENdbms_output.put_line(`> ClosePersona'); dbms_crypto_toolkit.ClosePersona(persona);END IF;
IF wallet_opened THENdbms_output.put_line(`> CloseWallet'); dbms_crypto_toolkit.CloseWallet(wallet);END IF;
IF initialized THENdbms_output.put_line(`> Terminate'); dbms_crypto_toolkit.TERMINATE;END IF; IF all_done = FALSE THENRAISE;
END;