Clean up key file save and load.

This commit is contained in:
Ian Gulliver
2015-02-07 13:25:46 -08:00
parent d90770fabe
commit 55ca78194c
6 changed files with 22 additions and 66 deletions

View File

@@ -4,6 +4,7 @@
#include <unistd.h>
#include <cassert>
#include <fstream>
#include <iostream>
#include <sodium/crypto_box.h>
@@ -46,6 +47,18 @@ void CryptoBase::DerivePublicKey(const std::string& secret_key, std::string* pub
public_key->assign((char*)buf, crypto_box_PUBLICKEYBYTES);
}
void CryptoBase::ReadKeyFromFile(const std::string& filename, std::string* key) {
std::fstream key_file(filename, std::fstream::in);
assert(!key_file.fail());
key_file >> *key;
}
void CryptoBase::WriteKeyToFile(const std::string& filename, const std::string& key) {
std::fstream key_file(filename, std::fstream::out);
assert(!key_file.fail());
key_file << key;
}
void CryptoBase::EncodeEncryptAppend(const std::string& secret_key, const std::string& public_key, const TLVNode& input, TLVNode* container) {
assert(secret_key.length() == crypto_box_SECRETKEYBYTES);
assert(public_key.length() == crypto_box_PUBLICKEYBYTES);