Remove hex encoding, just write binary files.

This commit is contained in:
Ian Gulliver
2015-02-05 17:18:44 +00:00
parent 18715be4b9
commit 524434813c
4 changed files with 3 additions and 19 deletions

View File

@@ -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) { void CryptoBase::GenKey(std::string* key) {
char buf[crypto_secretbox_KEYBYTES]; char buf[crypto_secretbox_KEYBYTES];
randombytes((unsigned char *)buf, crypto_secretbox_KEYBYTES); randombytes((unsigned char *)buf, crypto_secretbox_KEYBYTES);

View File

@@ -7,7 +7,6 @@ class CryptoBase {
CryptoBase(const int fd); CryptoBase(const int fd);
virtual ~CryptoBase(); virtual ~CryptoBase();
static std::string BinToHex(const std::string& bin);
static void GenKey(std::string* key); static void GenKey(std::string* key);
static void GenKeyPair(std::string* secret_key, std::string* public_key); static void GenKeyPair(std::string* secret_key, std::string* public_key);
virtual int OnReadable() = 0; virtual int OnReadable() = 0;

View File

@@ -19,8 +19,7 @@ int main(int argc, char *argv[]) {
std::cerr << "Failed to open key file" << std::endl; std::cerr << "Failed to open key file" << std::endl;
return 1; return 1;
} }
key_file << "# Shared secret key" << std::endl; key_file << key;
key_file << CryptoBase::BinToHex(key) << std::endl;
} }
return 0; return 0;

View File

@@ -19,8 +19,7 @@ int main(int argc, char *argv[]) {
std::cerr << "Failed to open secret key file" << std::endl; std::cerr << "Failed to open secret key file" << std::endl;
return 1; return 1;
} }
secret_key_file << "# Secret key" << std::endl; secret_key_file << secret_key;
secret_key_file << CryptoBase::BinToHex(secret_key) << std::endl;
} }
{ {
@@ -29,8 +28,7 @@ int main(int argc, char *argv[]) {
std::cerr << "Failed to open public key file" << std::endl; std::cerr << "Failed to open public key file" << std::endl;
return 1; return 1;
} }
public_key_file << "# Public key" << std::endl; public_key_file << public_key;
public_key_file << CryptoBase::BinToHex(public_key) << std::endl;
} }
return 0; return 0;