Back to the WFC main page
$Revision: 30 $
Description
This class encapsulates cryptographic keys.
Constructors
CCryptographicKey()
CCryptographicKey( HCRYPTKEY source_handle, BOOL automatically_destroy = TRUE )
-
Constructs a new object or allows you to treat an existing HCRYPTKEY as an object.
Data Members
None.
Methods
BOOL Decrypt( const CByteArray& data_to_decrypt,
CByteArray& decrypted_data,
BOOL this_is_the_last_chunk_of_data_to_be_decrypted = TRUE,
CCryptographicHash * hash_p = NULL,
DWORD flags = 0 )
-
This method decrypts data.
BOOL Destroy( void )
-
Destroys the key.
BOOL Encrypt( const CByteArray& data_to_encrypt,
CByteArray& encrypted_data,
BOOL this_is_the_last_chunk_to_be_encrypted = TRUE,
CCryptographicHash * hash_p = NULL,
DWORD flags = 0 )
-
This method encrypts data.
BOOL Export( CCryptographicKey& key_for_whoever_we_are_exporting_to,
CByteArray& key_in_exported_form,
DWORD export_format = formatSimple,
DWORD flags = 0 )
-
Exports the key so you can send it to others.
BOOL FromHandle( HCRYPTKEY source_handle, BOOL automatically_destroy = TRUE )
-
Tells the class to start playing with the HCRYPTKEY provided. If
automatically_destroy
is set to TRUE, Destroy() will be
called by the destructor.
BOOL GetAlgorithmIdentifier( DWORD& identifier )
-
Retrieves the identifier for the algorithm. It basically calls GetParameter()
with
parameterAlgorithmIdentifier
.
BOOL GetBlockLength( DWORD& block_length )
-
Retrieves the block length. It basically calls GetParameter()
with
parameterBlockLengthInBytes
.
BOOL GetCipherMode( DWORD& cipher_mode )
-
Retrieves the cipher mode. It basically calls GetParameter()
with
parameterCipherMode
.
The cipher_mode
will be set to one of the following:
- modeCipherBlockChaining
- modeCipherFeedback
- modeElectronicCodebook
- modeOutputFeedback
HCRYPTKEY GetHandle( void ) const
-
Returns the underlying HCRYPTKEY so you can call the API directly.
BOOL GetInitializationVector( CByteArray& initialization_vector )
-
Retrieves the initialization vector. It calls GetParameter() with
parameterInitializationVector
.
BOOL GetNumberOfBitsProcessedPerCycle( DWORD& number_of_bits )
-
Retrieves the
number of bits processed per cycle if the cipher mode is modeCipherFeedback or
modeOutputFeedback.
BOOL GetPaddingMode( DWORD& padding_mode )
-
Retrieves the padding mode. Currently the only padding mode is PKCS5_PADDING.
BOOL GetParameter( const DWORD parameter_to_get, BYTE *buffer, DWORD& buffer_length, const DWORD flags = 0 )
-
Retrieves one of the following bits of information (i.e.
parameter_to_get
can be one of):
- parameterAlgorithmIdentifier
- parameterBlockLengthInBytes
- parameterCipherMode
- parameterInitializationVector
- parameterNumberOfBitsProcessedPerCycle
- parameterPaddingMode
- parameterPermissions
- parameterSalt
BOOL GetPermissions( DWORD& permissions )
-
Retrieves the permissions.
BOOL GetSalt( CByteArray& salt )
-
Retrieves the Salt.
BOOL SetCipherMode( DWORD mode )
-
Sets the cipher mode to be used. The
mode
parameter can
be one of the following:
- modeCipherBlockChaining
- modeCipherFeedback
- modeElectronicCodebook
- modeOutputFeedback
BOOL SetInitializationVector( BYTE * buffer )
-
Sets the initialization vector.
BOOL SetNumberOfBitsProcessedPerCycle( DWORD number_of_bits )
-
Sets the number of bits
processed per cycle. This is valid only if the cipher mode is modeCipherFeedback
or modeOutputFeedback.
BOOL SetPaddingMode( DWORD mode )
-
Sets the padding mode to be used by the cipher.
BOOL SetParameter( const DWORD parameter_to_set, BYTE * buffer, const DWORD flags = 0 )
-
Sets a parameter of the key. You can set one of these parameters
(i.e.
parameter_to_set
can be one of these values):
- parameterCipherMode
- parameterInitializationVector
- parameterNumberOfBitsProcessedPerCycle
- parameterPaddingMode
- parameterPermissions
- parameterSalt
BOOL SetPermissions( DWORD permissions )
-
Sets permissions on the key. The
permissions
can be:
- permissionDecrypt
- permissionEncrypt
- permissionExport
- permissionMAC
- permissionRead
- permissionWrite
BOOL SetSalt( BYTE * buffer )
-
Sets the salt value.
Example
Sorry.
API's Used
- CryptDecrypt
- CryptDestroyKey
- CryptEncrypt
- CryptExportKey
- CryptGetKeyParam
- CryptSetKeyParam
Copyright, 2000, Samuel R. Blackburn
$Workfile: CCryptographicKey.cpp $
$Modtime: 1/04/00 5:09a $