GpgFrontend Project
A Free, Powerful, Easy-to-Use, Compact, Cross-Platform, and Installation-Free OpenPGP(pgp) Crypto Tool.
PassphraseGenerator.h
1
29#ifndef GPGFRONTEND_PASSPHRASEGENERATOR_H
30#define GPGFRONTEND_PASSPHRASEGENERATOR_H
31
32#include "core/GpgFrontendCore.h"
33#include "core/GpgFunctionObject.h"
34
35namespace GpgFrontend {
36
42class GPGFRONTEND_CORE_EXPORT PassphraseGenerator
43 : public SingletonFunctionObject<PassphraseGenerator> {
44 public:
53
60 std::string Generate(int len) {
61 std::uniform_int_distribution<int> dist(999, 99999);
62
63 auto file_string = boost::format("KeyPackage_%1%") % dist(mt_);
64 static const char alphanum[] =
65 "0123456789"
66 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
67 "abcdefghijklmnopqrstuvwxyz";
68 std::string tmp_str;
69 tmp_str.reserve(len);
70
71 for (int i = 0; i < len; ++i) {
72 tmp_str += alphanum[dist(mt_) % (sizeof(alphanum) - 1)];
73 }
74 return tmp_str;
75 }
76
77 std::random_device rd_;
78 std::mt19937 mt_ = std::mt19937(rd_());
79};
80
81} // namespace GpgFrontend
82
83#endif // GPGFRONTEND_PASSPHRASEGENERATOR_H
The PassphraseGenerator class.
Definition: PassphraseGenerator.h:43
std::random_device rd_
Random device.
Definition: PassphraseGenerator.h:77
std::string Generate(int len)
generate passphrase
Definition: PassphraseGenerator.h:60
PassphraseGenerator(int channel=SingletonFunctionObject::GetDefaultChannel())
PassphraseGenerator constructor.
Definition: PassphraseGenerator.h:50
Definition: GpgFunctionObject.h:49
static int GetDefaultChannel()
Get the Default Channel object.
Definition: GpgFunctionObject.h:127
Definition: CoreCommonUtil.cpp:29