1
0
mirror of https://github.com/PurpleI2P/i2pd-tools synced 2025-01-11 23:37:53 +00:00
i2pd-tools/keygen.cpp

41 lines
980 B
C++
Raw Normal View History

2016-09-16 15:28:01 +00:00
#include <iostream>
#include <fstream>
#include <stdlib.h>
#include "Crypto.h"
#include "Identity.h"
2016-10-10 11:59:54 +00:00
#include "common/key.hpp"
2016-09-16 15:28:01 +00:00
int main (int argc, char * argv[])
{
2016-10-10 11:18:33 +00:00
if (argc < 2)
2016-09-16 15:28:01 +00:00
{
2016-10-10 11:59:54 +00:00
std::cout << "Usage: keygen filename <signature type>" << std::endl;
2016-09-16 15:28:01 +00:00
return -1;
}
i2p::crypto::InitCrypto (false);
i2p::data::SigningKeyType type = i2p::data::SIGNING_KEY_TYPE_DSA_SHA1;
2016-10-10 11:59:54 +00:00
if (argc > 2) {
std::string str(argv[2]);
type = NameToSigType(str);
}
2016-09-16 15:28:01 +00:00
auto keys = i2p::data::PrivateKeys::CreateRandomKeys (type);
std::ofstream f (argv[1], std::ofstream::binary | std::ofstream::out);
if (f)
{
size_t len = keys.GetFullLen ();
uint8_t * buf = new uint8_t[len];
len = keys.ToBuffer (buf, len);
f.write ((char *)buf, len);
delete[] buf;
std::cout << "Destination " << keys.GetPublic ()->GetIdentHash ().ToBase32 () << " created" << std::endl;
}
else
std::cout << "Can't create file " << argv[1] << std::endl;
2017-02-20 21:08:17 +00:00
i2p::crypto::TerminateCrypto ();
2016-09-16 15:28:01 +00:00
return 0;
}