36 lines
931 B
C++
36 lines
931 B
C++
#include "KeyCodeHelper.h"
|
|
|
|
#include "lib/utils/datetime.h"
|
|
#include "lib/utils/crypto/CryptoInit.h"
|
|
#include "lib/utils/crypto/PrivateKey.h"
|
|
#include "lib/utils/crypto/PublicKey.h"
|
|
|
|
#include "lib/config/protos/keycode.pb.h"
|
|
#include <google/protobuf/text_format.h>
|
|
#include <google/protobuf/io/zero_copy_stream_impl.h>
|
|
#include <sstream>
|
|
#include <string>
|
|
|
|
namespace bts {
|
|
namespace crypto {
|
|
|
|
bool decrypt_keycode(const bts::crypto::PublicKey& public_key, const bts::config::EncryptedKeyCode& kc,
|
|
bts::config::KeyCode* dk)
|
|
{
|
|
std::stringstream kss, out;
|
|
kss << kc.keycode();
|
|
if(public_key.decrypt(kss, out))
|
|
{
|
|
bts::config::KeyCode kc;
|
|
google::protobuf::io::IstreamInputStream kc_stream(&kss);
|
|
google::protobuf::TextFormat::Parse(&kc_stream, &kc);
|
|
if(dk)
|
|
{
|
|
*dk = kc;
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
}} |