regaddr.cpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #include <iostream>
  2. #include <fstream>
  3. #include <sstream>
  4. #include "Identity.h"
  5. #include "Base.h"
  6. int main (int argc, char * argv[])
  7. {
  8. if (argc < 2)
  9. {
  10. std::cout << "Usage: regaddr filename address" << std::endl;
  11. return -1;
  12. }
  13. i2p::crypto::InitCrypto (false, true, true, false);
  14. i2p::data::PrivateKeys keys;
  15. std::ifstream s(argv[1], std::ifstream::binary);
  16. if (s.is_open ())
  17. {
  18. s.seekg (0, std::ios::end);
  19. size_t len = s.tellg();
  20. s.seekg (0, std::ios::beg);
  21. uint8_t * buf = new uint8_t[len];
  22. s.read ((char *)buf, len);
  23. if(keys.FromBuffer (buf, len))
  24. {
  25. auto signatureLen = keys.GetPublic ()->GetSignatureLen ();
  26. uint8_t * signature = new uint8_t[signatureLen];
  27. char * sig = new char[signatureLen*2];
  28. std::stringstream out;
  29. out << argv[2] << "="; // address
  30. out << keys.GetPublic ()->ToBase64 ();
  31. keys.Sign ((uint8_t *)out.str ().c_str (), out.str ().length (), signature);
  32. auto len = i2p::data::ByteStreamToBase64 (signature, signatureLen, sig, signatureLen*2);
  33. sig[len] = 0;
  34. out << "#!sig=" << sig;
  35. delete[] signature;
  36. delete[] sig;
  37. std::cout << out.str () << std::endl;
  38. }
  39. else
  40. std::cout << "Failed to load keyfile " << argv[1] << std::endl;
  41. delete[] buf;
  42. }
  43. i2p::crypto::TerminateCrypto ();
  44. return 0;
  45. }