Remove hex encoding, just write binary files.
This commit is contained in:
12
crypto.cc
12
crypto.cc
@@ -20,18 +20,6 @@ CryptoBase::~CryptoBase() {
|
||||
}
|
||||
}
|
||||
|
||||
std::string CryptoBase::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;
|
||||
}
|
||||
|
||||
void CryptoBase::GenKey(std::string* key) {
|
||||
char buf[crypto_secretbox_KEYBYTES];
|
||||
randombytes((unsigned char *)buf, crypto_secretbox_KEYBYTES);
|
||||
|
||||
1
crypto.h
1
crypto.h
@@ -7,7 +7,6 @@ class CryptoBase {
|
||||
CryptoBase(const int fd);
|
||||
virtual ~CryptoBase();
|
||||
|
||||
static std::string BinToHex(const std::string& bin);
|
||||
static void GenKey(std::string* key);
|
||||
static void GenKeyPair(std::string* secret_key, std::string* public_key);
|
||||
virtual int OnReadable() = 0;
|
||||
|
||||
@@ -19,8 +19,7 @@ int main(int argc, char *argv[]) {
|
||||
std::cerr << "Failed to open key file" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
key_file << "# Shared secret key" << std::endl;
|
||||
key_file << CryptoBase::BinToHex(key) << std::endl;
|
||||
key_file << key;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
@@ -19,8 +19,7 @@ int main(int argc, char *argv[]) {
|
||||
std::cerr << "Failed to open secret key file" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
secret_key_file << "# Secret key" << std::endl;
|
||||
secret_key_file << CryptoBase::BinToHex(secret_key) << std::endl;
|
||||
secret_key_file << secret_key;
|
||||
}
|
||||
|
||||
{
|
||||
@@ -29,8 +28,7 @@ int main(int argc, char *argv[]) {
|
||||
std::cerr << "Failed to open public key file" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
public_key_file << "# Public key" << std::endl;
|
||||
public_key_file << CryptoBase::BinToHex(public_key) << std::endl;
|
||||
public_key_file << public_key;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user