Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8069669
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T13:07:33+00:00 2026-06-05T13:07:33+00:00

I am writing an API in C for authenticating user using ONVIF. I write

  • 0

I am writing an API in C for authenticating user using ONVIF. I write some code to make authentication header. But when I sent these headers the server respond that “The security token could not be authenticated or authorized”

unsigned int nonce_int = 0, i = 0;
  time_t utcTime = 0;
  struct tm *timeInfo = NULL;
  char sha1_input[100] = { 0 };
  SHA1Context sha = { 0 };

  nonce_int = GetRandomNumber();
  encode_base64(sizeof(nonce_int), (char*)&nonce_int, nonceLen, noncestr);

  utcTime = time(NULL);
  timeInfo = localtime(&utcTime);
  strftime(timestr, timeLen, "%Y-%m-%dT%H:%M:%SZ", timeInfo);
  printf("\nTime in String Format = %s", timestr);

  sprintf(sha1_input, "%d+%d+%s", nonce_int, utcTime, password);

  SHA1Reset(&sha);
  SHA1Input(&sha, (const unsigned char*)sha1_input, strlen(sha1_input));

  if(!SHA1Result(&sha))
  {
    printf("\nERROR-- could not compute message digest");
  }
  else
  {
    memset(sha1_input, 0x00, sizeof(sha1_input));
    /*sprintf(sha1_input, "%X%X%X%X%X", sha.Message_Digest[0], sha.Message_Digest[1],
      sha.Message_Digest[2], sha.Message_Digest[3], sha.Message_Digest[4]);*/

    sprintf(sha1_input, "%u%u%u%u%u", sha.Message_Digest[0], sha.Message_Digest[1],
      sha.Message_Digest[2], sha.Message_Digest[3], sha.Message_Digest[4]);

    printf("\nSHA1 Digest = %s", sha1_input);
    encode_base64(strlen(sha1_input), sha1_input, digestLen, digeststr);
    printf("\nSHA1 Digest Base64 Encoded = %s", digeststr);
  }

after that I sent this request on HTTP using POST method this.

Response:

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope  xmlns:SOAP-ENV="http://www.w3.org/2003/05/soap-envelope" 
                    xmlns:SOAP-ENC="http://www.w3.org/2003/05/soap-encoding" 
                    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
                    xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
                    xmlns:wsa5="http://www.w3.org/2005/08/addressing" 
                    xmlns:c14n="http://www.w3.org/2001/10/xml-exc-c14n#" 
                    xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" 
                    xmlns:ds="http://www.w3.org/2000/09/xmldsig#" 
                    xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" 
                    xmlns:ptzimg2="http://www.onvif.org/ver10/schema" 
                    xmlns:ptzimg3="http://www.w3.org/2005/05/xmlmime" 
                    xmlns:ptzimg4="http://docs.oasis-open.org/wsn/b-2" 
                    xmlns:ptzimg5="http://docs.oasis-open.org/wsrf/bf-2" 
                    xmlns:ptzimg6="http://docs.oasis-open.org/wsn/t-1" 
                    xmlns:ptzimg1="http://www.onvif.org/ver20/ptz/wsdl" 
                    xmlns:ptzimg7="http://www.onvif.org/ver20/imaging/wsdl" 
                    xmlns:ter="http://www.onvif.org/ver10/error">

    <SOAP-ENV:Header></SOAP-ENV:Header>
    <SOAP-ENV:Body>
        <SOAP-ENV:Fault>
            <SOAP-ENV:Code>
                <SOAP-ENV:Value>
                    SOAP-ENV:Sender
                </SOAP-ENV:Value>
                <SOAP-ENV:Subcode>
                    <SOAP-ENV:Value>
                        wsse:FailedAuthentication
                    </SOAP-ENV:Value>
                </SOAP-ENV:Subcode>
            </SOAP-ENV:Code>
            <SOAP-ENV:Reason>
                <SOAP-ENV:Text xml:lang="en">
                    The security token could not be authenticated or authorized
                </SOAP-ENV:Text>
            </SOAP-ENV:Reason>
            <SOAP-ENV:Node>
                http://www.w3.org/2003/05/soap-envelope/node/ultimateReceiver
            </SOAP-ENV:Node>
            <SOAP-ENV:Role>
                http://www.w3.org/2003/05/soap-envelope/role/ultimateReceiver
            </SOAP-ENV:Role>
            <SOAP-ENV:Detail></SOAP-ENV:Detail>
        </SOAP-ENV:Fault>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

I synchronized the time. I think the problem is with my authentication headers. I did not find any useful documentation that specifies the exact data type and creation method for digest and other headers. any help will be appreciated. Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T13:07:34+00:00Added an answer on June 5, 2026 at 1:07 pm

    I figured out the problem. I was using local time string rather than utc time string. this solved my problem. thanks

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing an API for ONVIF authentication in C. I create WS-UsernameToken, But
I'm a C++ amateur. I'm writing some Win32 API code and there are handles
I'm trying to incorporate some Gravatar functionality using its XML-RPC API in an iPhone
I'm writing an API that converts actions performed by a non-technical user into Salesforce.com
As part of an API I am building, there is a user authentication method
I'm writing simple Android app to filter some events from user's calendar. The questions
I'm writing a test app using the twitter gem and I'd like to write
I'm writing an API that gets information about the CPU (using CPUID). What I'm
I could do with some help on my REST API. I'm writing a Node.js
I'm writing an authentication script in PHP, to be called as an API, that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.