66 string prog_description =
"NCBI encryption utility\n";
67 arg_desc->SetUsageContext(
GetArguments().GetProgramBasename(),
68 prog_description,
false);
70 arg_desc->AddFlag(
"encrypt",
"Encrypt input data (default action)",
true);
71 arg_desc->AddFlag(
"decrypt",
"Decrypt input data",
true);
72 arg_desc->AddFlag(
"generate_key",
"Generate encryption key",
true);
74 arg_desc->AddDefaultKey(
"i",
"Input",
76 arg_desc->AddDefaultKey(
"o",
"Output",
78 arg_desc->AddOptionalKey(
"password",
"Password",
80 arg_desc->AddOptionalKey(
"domain",
"Domain",
83 arg_desc->AddOptionalKey(
"severity",
"Severity",
84 "Log message severity when reporting an outdated key usage",
86 arg_desc->SetConstraint(
"severity",
89 .AllowValue(
"Warning")
91 .AllowValue(
"Critical"));
108 if ( args[
"generate_key"] ) {
111 else if ( args[
"decrypt"] ) {
125 if ( args[
"password"] ) {
126 seed = args[
"password"].AsString();
132 for (
size_t i = 0;
i <
seed.size();
i++) {
139 if ( args[
"severity"] ) {
140 out <<
"/" << args[
"severity"].AsString();
155 if ( args[
"password"] ) {
158 else if ( args[
"domain"] ) {
181 if ( args[
"password"] ) {
184 else if ( args[
"domain"] ) {
200 int main(
int argc,
const char* argv[])
int Run(void)
Run the application.
void Init(void)
Initialize the application.
static string GenerateKey(const string &seed)
Generate an encryption/decryption key from the seed string.
static string DecryptForDomain(const string &encrypted_string, const string &domain)
Decrypt data using domain key.
static string EncryptForDomain(const string &original_string, const string &domain)
Encrypt data using domain key.
static string Encrypt(const string &original_string)
Encrypt a string using key from the 1st line of the 1st NCBI keys file.
static string Decrypt(const string &encrypted_string)
Decrypt a string using the matching key found in the NCBI keys files.
CNcbiOstrstreamToString class helps convert CNcbiOstrstream to a string Sample usage:
std::ofstream out("events_result.xml")
main entry point for tests
virtual const CArgs & GetArgs(void) const
Get parsed command line arguments.
int AppMain(int argc, const char *const *argv, const char *const *envp=0, EAppDiagStream diag=eDS_Default, const char *conf=NcbiEmptyCStr, const string &name=NcbiEmptyString)
Main function (entry point) for the NCBI application.
virtual void SetupArgDescriptions(CArgDescriptions *arg_desc)
Setup the command line argument descriptions.
const CNcbiArguments & GetArguments(void) const
Get the application's cached unprocessed command-line arguments.
@ eRequires
One argument requires another.
@ eExcludes
One argument excludes another.
@ eInputFile
Name of file (must exist and be readable)
@ eString
An arbitrary string.
@ eOutputFile
Name of file (must be writable)
TValue GetRand(void)
Get the next random number in the interval [0..GetMax()] (inclusive)
void Randomize(void)
Re-initialize (re-seed) the generator using platform-specific randomization.
IO_PREFIX::ostream CNcbiOstream
Portable alias for ostream.
IO_PREFIX::istream CNcbiIstream
Portable alias for istream.
static void TruncateSpacesInPlace(string &str, ETrunc where=eTrunc_Both)
Truncate spaces in a string (in-place)
const struct ncbi::grid::netcache::search::fields::KEY key
int main(int argc, const char *argv[])
Defines the CNcbiApplication and CAppException classes for creating NCBI applications.
Defines command line argument related classes.
std::istream & in(std::istream &in_, double &x_)
Defines NCBI C++ secure resources API.