Add gen-pubkeypair
This commit is contained in:
9
Makefile
9
Makefile
@@ -1,4 +1,7 @@
|
||||
all: server
|
||||
all: auth-server gen-pubkeypair
|
||||
|
||||
server: server.cc
|
||||
g++ -o server server.cc nacl/build/instance1/lib/amd64/randombytes.o nacl/build/instance1/lib/amd64/libnacl.a
|
||||
auth-server: auth-server.cc
|
||||
g++ -o auth-server auth-server.cc nacl/build/instance1/lib/amd64/randombytes.o nacl/build/instance1/lib/amd64/libnacl.a
|
||||
|
||||
gen-pubkeypair: gen-pubkeypair.cc
|
||||
g++ -o gen-pubkeypair gen-pubkeypair.cc nacl/build/instance1/lib/amd64/randombytes.o nacl/build/instance1/lib/amd64/libnacl.a
|
||||
|
||||
30
gen-pubkeypair.cc
Normal file
30
gen-pubkeypair.cc
Normal file
@@ -0,0 +1,30 @@
|
||||
#include <iostream>
|
||||
|
||||
#include "nacl/build/instance1/include/amd64/crypto_box.h"
|
||||
|
||||
class CryptoBase {
|
||||
public:
|
||||
static const std::string BinToHex(const std::string& bin) {
|
||||
static const char *hex = "0123456789ABCDEF";
|
||||
std::string ret;
|
||||
ret.reserve(bin.length() * 2);
|
||||
for (size_t i = 0; i < bin.length(); i++) {
|
||||
const char c = bin[i];
|
||||
ret.push_back(hex[(c & 0xf0) >> 4]);
|
||||
ret.push_back(hex[c & 0x0f]);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
};
|
||||
|
||||
int main() {
|
||||
std::string pk;
|
||||
std::string sk;
|
||||
|
||||
pk = crypto_box_keypair(&sk);
|
||||
|
||||
std::cout << "Secret: " << CryptoBase::BinToHex(sk) << std::endl;
|
||||
std::cout << "Public: " << CryptoBase::BinToHex(pk) << std::endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user