[xmlsec] Regarding Hmac-SHA1 signing.
Venkataragavan Vijayakumar
venkataragavan.v at gmail.com
Thu Oct 10 02:15:38 PDT 2013
Hi,
I have written the follwing code to sign the element in the document using
HMAC-SHA1 Algorithm. I have taken the sample code from this mailing list.
My doubt is that code contains API like CreateHmackey. Whether it is for
Hmac-sha1 or for Hmac only.
If i asked silly question please forgive me.
Please let me this code is for HMAC-SHA1 signing.
The code is:
sign(xmlNodePtr g_SignatureNode, const char* keybuf)
{
dsigCtx = xmlSecDSigCtxCreate(NULL);
if(dsigCtx == NULL) {
fprintf(stderr,"Error: failed to create signature context\n");
goto done;
}
dsigCtx->signKey = CreateHmacKey(keybuf, keysize);
xmlSecDSigCtxSign(dsigCtx, g_SignatureNode)
}
xmlSecKeyPtr CreateHmacKey(const xmlSecByte * buf, xmlSecSize size)
{
xmlSecKeyPtr key;
xmlSecKeyDataPtr key_data;
int ret;
const unsigned char *p = buf;
key = xmlSecKeyCreate();
if(!key) {
return (NULL);
}
key_data = xmlSecKeyDataCreate(xmlSecKeyDataHmacId);
if(!key_data) {
xmlSecKeyDestroy(key);
return (NULL);
}
ret = xmlSecKeySetValue(key, key_data);
if(ret < 0) {
xmlSecKeyDataDestroy(key_data);
xmlSecKeyDestroy(key);
return (NULL);
}
ret = xmlSecOpenSSLKeyDataHmacSet(key_data, buf, size);
if(ret < 0) {
xmlSecKeyDestroy(key);
return (NULL);
}
return (key);
}
Thanks,
Venkat.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.aleksey.com/pipermail/xmlsec/attachments/20131010/1148e41c/attachment.html>
More information about the xmlsec
mailing list