activemq-cpp-3.9.0
decaf::security::MessageDigest Class Reference

This MessageDigest class provides applications the functionality of a message digest algorithm, such as MD5 or SHA. More...

#include <src/main/decaf/security/MessageDigest.h>

Public Member Functions

virtual ~MessageDigest ()
 
std::vector< unsigned char > digest ()
 Completes the hash computation by performing final operations such as padding. More...
 
int digest (unsigned char *input, int size, int offset, int length)
 Completes the hash computation by performing final operations such as padding. More...
 
std::vector< unsigned char > digest (const unsigned char *input, int size)
 Performs a final update on the digest using the specified array of bytes, then completes the digest computation. More...
 
std::vector< unsigned char > digest (const std::vector< unsigned char > &input)
 Performs a final update on the digest using the specified array of bytes, then completes the digest computation. More...
 
std::string getAlgorithmName () const
 Returns a string that identifies the algorithm, independent of implementation details. More...
 
const ProvidergetProvider () const
 Returns the Provider associated with this MessageDigest. More...
 
int getDigestLength () const
 Returns the length of the digest in bytes, or 0 if this operation is not supported by the provider and the implementation is not cloneable. More...
 
MessageDigestclone ()
 Returns a clone of this MessageDisgest instance if the MessageDigestSpi in use is cloneable. More...
 
void reset ()
 Resets the digest for further use. More...
 
std::string toString () const
 Returns a string representation of this message digest object. More...
 
void update (unsigned char input)
 Updates the digest using the specified byte. More...
 
void update (unsigned char *input, int size, int offset, int length)
 Updates the digest using the specified array of bytes, starting at the specified offset. More...
 
void update (const std::vector< unsigned char > &input)
 Updates the digest using the specified array of bytes. More...
 
void update (nio::ByteBuffer &input)
 Update the digest using the specified ByteBuffer. More...
 

Static Public Member Functions

static MessageDigestgetInstance (const std::string &algorithm)
 Returns a MessageDigest object that implements the specified digest algorithm. More...
 
static bool isEqual (const std::vector< unsigned char > &digesta, const std::vector< unsigned char > &digestb)
 Compares two digests for equality. More...
 

Protected Member Functions

 MessageDigest (const std::string &name)
 

Detailed Description

This MessageDigest class provides applications the functionality of a message digest algorithm, such as MD5 or SHA.

Message digests are secure one-way hash functions that take arbitrary-sized data and output a fixed-length hash value.

A MessageDigest object starts out initialized. The data is processed through it using the update methods. At any point reset can be called to reset the digest. Once all the data to be updated has been updated, one of the digest methods should be called to complete the hash computation.

The digest method can be called once for a given number of updates. After digest has been called, the MessageDigest object is reset to its initialized state.

Implementations are free to implement the clone method. Client applications can test cloneability by attempting cloning and catching the CloneNotSupportedException:

MessageDigest* md = MessageDigest::getInstance("SHA");

try { md->update(toChapter1); MessageDigest* tc1 = md.clone(); byte[] toChapter1Digest = tc1.digest(); md.update(toChapter2); ...etc. } catch (CloneNotSupportedException& ex) { throw DigestException("couldn't make digest of partial content"); }

Note that if a given implementation is not cloneable, it is still possible to compute intermediate digests by instantiating several instances, if the number of digests is known in advance.

See also
MessageDigestSpi
Since
1.0

Constructor & Destructor Documentation

decaf::security::MessageDigest::MessageDigest ( const std::string &  name)
protected
virtual decaf::security::MessageDigest::~MessageDigest ( )
virtual

Member Function Documentation

MessageDigest* decaf::security::MessageDigest::clone ( )

Returns a clone of this MessageDisgest instance if the MessageDigestSpi in use is cloneable.

Returns
a clone of this MessageDigest if possible.
Exceptions
CloneNotSupportedExceptionif the SPI in use cannot be cloned.
std::vector<unsigned char> decaf::security::MessageDigest::digest ( )

Completes the hash computation by performing final operations such as padding.

The digest is reset after this call is made.

int decaf::security::MessageDigest::digest ( unsigned char *  input,
int  size,
int  offset,
int  length 
)

Completes the hash computation by performing final operations such as padding.

The digest is reset after this call is made.

Parameters
inputThe output buffer for the computed digest.
sizeThe size of the given input buffer.
offsetThe offset into the output buffer to begin storing the digest.
lengthThe number of bytes within buf allotted for the digest.
Returns
the number of bytes placed into buffer.
Exceptions
DigestExceptionif an error occurs.
std::vector<unsigned char> decaf::security::MessageDigest::digest ( const unsigned char *  input,
int  size 
)

Performs a final update on the digest using the specified array of bytes, then completes the digest computation.

That is, this method first calls update(input), passing the input array to the update method, then calls digest().

Parameters
inputThe input to be updated before the digest is completed.
sizeThe length in bytes of the input buffer.
Returns
the array of bytes for the resulting hash value.
std::vector<unsigned char> decaf::security::MessageDigest::digest ( const std::vector< unsigned char > &  input)

Performs a final update on the digest using the specified array of bytes, then completes the digest computation.

That is, this method first calls update(input), passing the input array to the update method, then calls digest().

Parameters
inputThe input to be updated before the digest is completed.
Returns
the array of bytes for the resulting hash value.
std::string decaf::security::MessageDigest::getAlgorithmName ( ) const
inline

Returns a string that identifies the algorithm, independent of implementation details.

The name should be a standard name (such as "SHA", "MD5", etc).

Returns
the algorithm name.
int decaf::security::MessageDigest::getDigestLength ( ) const

Returns the length of the digest in bytes, or 0 if this operation is not supported by the provider and the implementation is not cloneable.

Returns
the digest length in bytes, or 0 if this operation is not supported by the provider and the implementation is not cloneable.
static MessageDigest* decaf::security::MessageDigest::getInstance ( const std::string &  algorithm)
static

Returns a MessageDigest object that implements the specified digest algorithm.

This method traverses the list of registered security Providers, starting with the most preferred Provider. A new MessageDigest object encapsulating the MessageDigestSpi implementation from the first Provider that supports the specified algorithm is returned.

Note that the list of registered providers may be retrieved via the Security.getProviders() method.

Parameters
algorithmThe name of the algorithm requested. (MD5, SHA-1, etc)
Returns
a Message Digest object that implements the specified algorithm.
Exceptions
NoSuchAlgorithmExceptionif no Provider supports a MessageDigestSpi implementation for the specified algorithm.
const Provider* decaf::security::MessageDigest::getProvider ( ) const
inline

Returns the Provider associated with this MessageDigest.

The pointer returned by this method remains the property of the Security framework and should be deleted by the calling application at any time.

Returns
the provider associated with this MessageDigest.
static bool decaf::security::MessageDigest::isEqual ( const std::vector< unsigned char > &  digesta,
const std::vector< unsigned char > &  digestb 
)
static

Compares two digests for equality.

Does a simple byte compare.

Parameters
digestaThe first digest for comparison.
digestbThe second digest for comparison.
Returns
true if the two digests are equal.
void decaf::security::MessageDigest::reset ( )

Resets the digest for further use.

std::string decaf::security::MessageDigest::toString ( ) const

Returns a string representation of this message digest object.

Returns
a string representation of this message digest object.
void decaf::security::MessageDigest::update ( unsigned char  input)

Updates the digest using the specified byte.

Parameters
inputThe byte with which to update the digest.
void decaf::security::MessageDigest::update ( unsigned char *  input,
int  size,
int  offset,
int  length 
)

Updates the digest using the specified array of bytes, starting at the specified offset.

Parameters
inputThe array of bytes.
sizeThe size of the given input buffer.
offsetThe offset to start from in the array of bytes.
lengthThe number of bytes to use, starting at offset.
void decaf::security::MessageDigest::update ( const std::vector< unsigned char > &  input)

Updates the digest using the specified array of bytes.

Parameters
inputThe array of bytes to use for the update.
void decaf::security::MessageDigest::update ( nio::ByteBuffer input)

Update the digest using the specified ByteBuffer.

The digest is updated using the input.remaining() bytes starting at input.position(). Upon return, the buffer's position will be equal to its limit; its limit will not have changed.

Parameters
inputThe input ByteBuffer to use for the update.

The documentation for this class was generated from the following file: