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
35
namespace
GpgFrontend
{
36
42
class
GPGFRONTEND_CORE_EXPORT
PassphraseGenerator
43
:
public
SingletonFunctionObject
<PassphraseGenerator> {
44
public
:
50
explicit
PassphraseGenerator
(
51
int
channel =
SingletonFunctionObject::GetDefaultChannel
())
52
:
SingletonFunctionObject
<
PassphraseGenerator
>(channel) {}
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
GpgFrontend::PassphraseGenerator
The PassphraseGenerator class.
Definition:
PassphraseGenerator.h:42
GpgFrontend::SingletonFunctionObject
Definition:
GpgFunctionObject.h:148
GpgFrontend
Definition:
CoreCommonUtil.cpp:29
GpgFrontend::PassphraseGenerator::Generate
std::string Generate(int len)
generate passphrase
Definition:
PassphraseGenerator.h:60
GpgFrontend::PassphraseGenerator::rd_
std::random_device rd_
Random device.
Definition:
PassphraseGenerator.h:77
GpgFrontend::PassphraseGenerator::PassphraseGenerator
PassphraseGenerator(int channel=SingletonFunctionObject::GetDefaultChannel())
PassphraseGenerator constructor.
Definition:
PassphraseGenerator.h:50
GpgFrontend::SingletonFunctionObject::GetDefaultChannel
static int GetDefaultChannel()
Get the Default Channel object.
Definition:
GpgFunctionObject.h:232
src
core
function
PassphraseGenerator.h
Generated by
1.8.17