activemq-cpp-3.9.0
|
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 Provider * | getProvider () 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... | |
MessageDigest * | clone () |
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 MessageDigest * | getInstance (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) | |
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.
|
protected |
|
virtual |
MessageDigest* decaf::security::MessageDigest::clone | ( | ) |
Returns a clone of this MessageDisgest instance if the MessageDigestSpi in use is cloneable.
CloneNotSupportedException | if 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.
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. |
DigestException | if 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().
input | The input to be updated before the digest is completed. |
size | The length in bytes of the input buffer. |
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().
input | The input to be updated before the digest is completed. |
|
inline |
Returns a string that identifies the algorithm, independent of implementation details.
The name should be a standard name (such as "SHA", "MD5", etc).
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.
|
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.
algorithm | The name of the algorithm requested. (MD5, SHA-1, etc) |
NoSuchAlgorithmException | if no Provider supports a MessageDigestSpi implementation for the specified algorithm. |
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.
|
static |
Compares two digests for equality.
Does a simple byte compare.
digesta | The first digest for comparison. |
digestb | The second digest for comparison. |
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.
void decaf::security::MessageDigest::update | ( | unsigned char | input | ) |
Updates the digest using the specified byte.
input | The 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.
input | The array of bytes. |
size | 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 | ( | const std::vector< unsigned char > & | input | ) |
Updates the digest using the specified array of bytes.
input | The 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.
input | The input ByteBuffer to use for the update. |