Skip to content

Instantly share code, notes, and snippets.

@g40
Created October 18, 2016 11:02
Show Gist options
  • Save g40/4dd78be7fec672e1cd8040d1e7d96b75 to your computer and use it in GitHub Desktop.
Save g40/4dd78be7fec672e1cd8040d1e7d96b75 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <string>
#include <vector>
#include <cryptopp/base64.h>
#include <cryptopp/sha.h>
std::string nonce = "LKqI6G/AikKCQrN0zqZFlg==";
std::string dt = "2010-09-16T07:50:45Z";
std::string pwd = "userpassword";
int main(int argc, char* argv[])
{
CryptoPP::Base64Decoder decoder;
decoder.Put((byte*)nonce.data(), nonce.size());
decoder.MessageEnd();
std::vector<uint8_t> bytes(decoder.MaxRetrievable(),0);
decoder.Get(&bytes[0],bytes.size());
CryptoPP::SHA1 hash;
byte digest[CryptoPP::SHA1::DIGESTSIZE];
hash.Update(bytes.data(), bytes.size());
hash.Update((const byte*)dt.c_str(), dt.size());
hash.Update((const byte*)pwd.c_str(), pwd.size());
hash.Final(digest);
CryptoPP::Base64Encoder encoder;
encoder.Put(digest, 20);
encoder.MessageEnd();
std::string hash64(encoder.MaxRetrievable(), 0);
encoder.Get((byte*)hash64.data(), hash64.size());
std::cout << hash64 << std::endl;
return 0;
}
@g40
Copy link
Author

g40 commented Oct 18, 2016

How to use Crypto++ to generate an ONVIF authentication hash as per section 6.1.1.3 of the spec here: http://www.onvif.org/Portals/0/documents/WhitePapers/ONVIF_WG-APG-Application_Programmer's_Guide.pdf

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment