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 8068573
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T12:43:59+00:00 2026-06-05T12:43:59+00:00

I am writing an API for ONVIF authentication in C. I create WS-UsernameToken, But

  • 0

I am writing an API for ONVIF authentication in C. I create WS-UsernameToken, But it is not working. Is there any problem with this WS-UsernameToken.

  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);
  sprintf(sha1_input, "%d%s%s", nonce_int, timestr, password);

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

  if(!SHA1Result(&sha))
  {
    printf("\nERROR-- could not compute message digest");
  }
  else
  {
    int i = 0;
    memset(sha1_input, 0x00, sizeof(sha1_input));

    for(i = 0; i < 5; i++)
    {
      sha.Message_Digest[i] = ntohl(sha.Message_Digest[i]);
    }

   encode_base64(sizeof(sha.Message_Digest), (unsigned char*)sha.Message_Digest, digestLen, digeststr);        
  }

  return 0;

But when I use these values and send ONVIF request. It replies that “The security token could not be authenticated or authorized”. I was wondering where I am making mistakes.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-05T12:44:02+00:00Added an answer on June 5, 2026 at 12:44 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

When writing an API or reusable object, is there any technical reason why all
Ok, this is a doubt I always have when I'm writing any API, a.k.a.,
I'm a C++ amateur. I'm writing some Win32 API code and there are handles
I'm currently writing the documentation for the API of my website. I'm not sure
I am writing an Objective-C class but it uses an API written in C.
I am writing an API in C for authenticating user using ONVIF. I write
I'm writing an api in node.js. The first webservice endpoint - /create - creates
I am writing a Windows Api wrapper and I have run into a problem.
Are there any sorts of useful idioms I can make use of when writing
I'm writing a REST API in PHP and I can't find any resources explaining

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.