24bool got_password =
false;
26bool got_algorithm =
false;
28bool got_key_length =
false;
29int iteration_count = -1;
30bool got_iteration_count =
false;
36 <<
" pencrypt [opts] file [file2 file3 ...]\n"
37 <<
" pencrypt -o dest_file file\n\n"
39 <<
"This program will apply an encryption algorithm to a file (or multiple files),\n"
40 <<
"creating an encrypted version of each file which can only be recovered using\n"
41 <<
"pdecrypt and the same password that was supplied to pencrypt. The compressed\n"
42 <<
"versions are written to a file with the same name as the original, but the\n"
43 <<
"extension .pe added to the filename, and the original file is removed\n"
44 <<
"(unless the version with -o is used, in which case you can encrypt only one\n"
45 <<
"file, you specify the destination file name, and the original file is not\n"
49 <<
"Note that if you are adding files to a Panda multifile (.mf file) with\n"
50 <<
"the multify command, it is not necessary to encrypt them separately;\n"
51 <<
"multify has an inline encryption option.\n\n"
55 <<
" -p \"password\"\n"
56 <<
" Specifies the password to use for encryption. There are no\n"
57 <<
" restrictions on the password length or contents, but longer passwords\n"
58 <<
" are more secure. If this is not specified, the user is prompted from\n"
59 <<
" standard input.\n\n"
61 <<
" -t Read the file as a text file. This will automatically convert\n"
62 <<
" universal end-of-line characters into a newline character, ascii\n"
65 <<
" -a \"algorithm\"\n"
66 <<
" Specifies the particular encryption algorithm to use. The complete\n"
67 <<
" set of available algorithms is defined by the current version of\n"
68 <<
" OpenSSL. The default algorithm is taken from the encryption-\n"
69 <<
" algorithm config variable.\n\n"
72 <<
" Specifies the key length, in bits, for the selected encryption\n"
73 <<
" algorithm. This only makes sense for those algorithms that support\n"
74 <<
" a variable key length. The default value is taken from the\n"
75 <<
" encryption-key-length config variable.\n\n"
77 <<
" -i iteration_count\n"
78 <<
" Specifies the number of times the password is hashed to generate\n"
79 <<
" a key. The only purpose of this is to make it computationally\n"
80 <<
" more expensive for an attacker to search the key space exhaustively.\n"
81 <<
" This should be a multiple of 1,000 and should not exceed about 65\n"
82 <<
" million; the value 0 indicates just one application of the hashing\n"
83 <<
" algorithm. The default value is taken from the encryption-iteration-\n"
84 <<
" count config variable.\n\n";
88main(
int argc,
char **argv) {
91 const char *optstr =
"o:p:ta:k:i:h";
94 bool got_dest_filename =
false;
95 bool text_file =
false;
98 int flag = getopt(argc, argv, optstr);
100 while (flag != EOF) {
104 got_dest_filename =
true;
118 got_algorithm =
true;
122 key_length = atoi(optarg);
123 got_key_length =
true;
127 iteration_count = atoi(optarg);
128 got_iteration_count =
true;
137 flag = getopt(argc, argv, optstr);
148 if (got_dest_filename && argc > 2) {
149 cerr <<
"Only one input file allowed in conjunction with -o.\n";
154 for (
int i = 1; i < argc; i++) {
157 cerr << source_file <<
" already ends .pe; skipping.\n";
160 if (!got_dest_filename) {
165 pifstream read_stream;
171 if (!source_file.
open_read(read_stream)) {
172 cerr <<
"Couldn't read: " << source_file << endl;
177 pofstream write_stream;
179 if (!dest_file.
open_write(write_stream,
true)) {
180 cerr <<
"Failed to open: " << dest_file << endl;
186 cerr <<
"Enter password: ";
187 std::getline(std::cin, password);
191 cerr << dest_file <<
"\n";
192 bool success = encrypt_stream(read_stream, write_stream, password,
193 algorithm, key_length, iteration_count);
196 write_stream.close();
199 cerr <<
"Failure writing " << dest_file <<
"\n";
204 if (!got_dest_filename) {
The name of a file, such as a texture file or an Egg file.
bool open_read(std::ifstream &stream) const
Opens the indicated ifstream for reading the file, if possible.
bool unlink() const
Permanently deletes the file associated with the filename, if possible.
void set_binary()
Indicates that the filename represents a binary file.
void set_text()
Indicates that the filename represents a text file.
std::string get_fullpath() const
Returns the entire filename: directory, basename, extension.
static Filename from_os_specific(const std::string &os_specific, Type type=T_general)
This named constructor returns a Panda-style filename (that is, using forward slashes,...
bool open_write(std::ofstream &stream, bool truncate=true) const
Opens the indicated ifstream for writing the file, if possible.
std::string get_extension() const
Returns the file extension.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void preprocess_argv(int &argc, char **&argv)
Processes the argc, argv pair as needed before passing it to getopt().
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.