- static char DIGITS[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
-
- auto_ptr<XSECCryptoHash> hasher(XSECPlatformUtils::g_cryptoProvider->hashSHA1());
- if (hasher.get()) {
- unsigned char buf[21];
- hasher->hash(reinterpret_cast<unsigned char*>(const_cast<char*>(s)),strlen(s));
- if (hasher->finish(buf,20)==20) {
- string ret;
- if (toHex) {
- for (unsigned int i=0; i<20; i++) {
- ret+=(DIGITS[((unsigned char)(0xF0 & buf[i])) >> 4 ]);
- ret+=(DIGITS[0x0F & buf[i]]);
- }
- }
- else {
- for (unsigned int i=0; i<20; i++) {
- ret+=buf[i];
- }
- }
- return ret;
- }
- }
- throw XMLSecurityException("Unable to generate SHA-1 hash.");
+ return SecurityHelper::doHash("SHA1", s, strlen(s), toHex);