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.
int digest (unsigned char *input, int size, int offset, int length)
 Completes the hash computation by performing final operations such as padding.
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.
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.
std::string getAlgorithmName () const
 Returns a string that identifies the algorithm, independent of implementation details.
const ProvidergetProvider () const
 Returns the Provider associated with this MessageDigest.
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.
MessageDigestclone ()
 Returns a clone of this MessageDisgest instance if the MessageDigestSpi in use is cloneable.
void reset ()
 Resets the digest for further use.
std::string toString () const
 Returns a string representation of this message digest object.
void update (unsigned char input)
 Updates the digest using the specified byte.
void update (unsigned char *input, int size, int offset, int len)
 Updates the digest using the specified array of bytes, starting at the specified offset.
void update (const std::vector< unsigned char > &input)
 Updates the digest using the specified array of bytes.
void update (nio::ByteBuffer &input)
 Update the digest using the specified ByteBuffer.

Static Public Member Functions

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

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:
CloneNotSupportedException if the SPI in use cannot be cloned.
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:
input The input to be updated before the digest is completed.
Returns:
the array of bytes for the resulting hash value.
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:
input The input to be updated before the digest is completed.
size The length in bytes of the input buffer.
Returns:
the array of bytes for the resulting hash value.
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:
input The output buffer for the computed digest.
size The size of the given input buffer.
offset The offset into the output buffer to begin storing the digest.
length The number of bytes within buf allotted for the digest.
Returns:
the number of bytes placed into buffer.
Exceptions:
DigestException if an error occurs.
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.

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:
algorithm The name of the algorithm requested. (MD5, SHA-1, etc)
Returns:
a Message Digest object that implements the specified algorithm.
Exceptions:
NoSuchAlgorithmException if 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:
digesta The first digest for comparison.
digesta The 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 ( 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:
input The input ByteBuffer to use for the update.
void decaf::security::MessageDigest::update ( const std::vector< unsigned char > &  input  ) 

Updates the digest using the specified array of bytes.

Parameters:
input The array of bytes to use for the update.
void decaf::security::MessageDigest::update ( unsigned char *  input,
int  size,
int  offset,
int  len 
)

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

Parameters:
input The array of bytes.
input The size of the given input buffer.
offset The offset to start from in the array of bytes.
length The number of bytes to use, starting at offset.
void decaf::security::MessageDigest::update ( unsigned char  input  ) 

Updates the digest using the specified byte.

Parameters:
input The byte with which to update the digest.

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

Generated on 1 Dec 2014 for activemq-cpp-3.8.2 by  doxygen 1.6.1