static bool matches(const XSECCryptoKey& key1, const XSECCryptoKey& key2);
/**
- * Performs a hash operation over the supplied data and returns a hex-encoded string.
+ * Performs a hash operation over the supplied data.
*
* @param hashAlg name of hash algorithm, syntax specific to crypto provider
* @param buf input data to hash
* @param buflen length of input data
- * @return hex-encoded result of hash operation, or an empty string
+ * @param toHex if true, hex-encodes the resulting raw bytes
+ * @return result of hash operation, or an empty string
*/
- static std::string doHash(const char* hashAlg, const char* buf, unsigned long buflen);
+ static std::string doHash(const char* hashAlg, const char* buf, unsigned long buflen, bool toHex=true);
/**
* Returns the base64-encoded DER encoding of a public key in SubjectPublicKeyInfo format.
return false;
}
-string SecurityHelper::doHash(const char* hashAlg, const char* buf, unsigned long buflen)
+string SecurityHelper::doHash(const char* hashAlg, const char* buf, unsigned long buflen, bool toHex)
{
static char DIGITS[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
string ret;
);
return ret;
}
- for (unsigned int i=0; i < len; ++i) {
- ret+=(DIGITS[((unsigned char)(0xF0 & digest[i])) >> 4 ]);
- ret+=(DIGITS[0x0F & digest[i]]);
+ if (toHex) {
+ for (int i=0; i < len; ++i) {
+ ret += (DIGITS[((unsigned char)(0xF0 & digest[i])) >> 4 ]);
+ ret += (DIGITS[0x0F & digest[i]]);
+ }
+ }
+ else {
+ for (int i=0; i < len; ++i) {
+ ret += digest[i];
+ }
}
return ret;
}