File: driver.cc

package info (click to toggle)
bobcat 6.11.00-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 15,292 kB
  • sloc: cpp: 21,370; fortran: 6,507; makefile: 2,787; sh: 724; perl: 401; ansic: 26
file content (62 lines) | stat: -rw-r--r-- 1,725 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include <iostream>
#include <fstream>
#include <string>

#include <bobcat/osymcryptstream>

using namespace std;
using namespace FBB;

int main(int argc, char **argv)
try
{
    if (argc == 1)
    {
        cout << "arg[1]: e - encrypt, d - decrypt,\n"
                "arg[2]: file to process, arg[3]: processed file\n";
        return 0;
    }

    string key = "0123456789abcdef0123456789abcdef";
    cout << "encryption key ? ";
    cin >> key;
    while (key.size() < 32)
        key += key;
    string iv = " 0123456789ab" "456";

    char cipherName[] =
        "AES-256-GCM"
        //"AES-256-CBC"
    ;

    ifstream in{ argv[2] };
    ofstream out{ argv[3] };

    if (*argv[1] == 'e')
    {
        OSymCryptStream<ENCRYPT> enc{ out, cipherName, key, iv, 100 };
            // comment out the above statement and uncomment the next
            // to use the constructor expecting a string as 1st arg:
//      OSymCryptStream<ENCRYPT> enc{ argv[3], cipherName, key, 
//                                    iv, 100 };

        enc << in.rdbuf() << eoi;
        //in.seekg(0);              // when activated, this won't
        //enc << in.rdbuf();        // be processed due to '<< eoi'
    }
    else
    {
        OSymCryptStream<DECRYPT> decrypt{ out, cipherName, key, 
                                                           iv, 100 };
            // comment out the above statement and uncomment the next
            // to use the constructor expecting a string as 1st arg:
//      OSymCryptStream<DECRYPT> decrypt{ argv[3], cipherName, key, 
//                                        iv, 100 };

        decrypt << in.rdbuf() << eoi;
    }
}
catch (exception const &exc)
{
    cerr << exc.what() << '\n';
}