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 (61 lines) | stat: -rw-r--r-- 1,557 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
#include <iostream>
#include <fstream>
#include <string>

#include <bobcat/isymcryptstream>
#include <bobcat/isymcryptstreambuf>

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";
    string iv = " 0123456789ab" "456";

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

    ifstream in = Exception::factory<ifstream>(argv[2]);
    ofstream out{ argv[3] };

    ISymCryptStreambuf<ENCRYPT> encbuf{ in, cipherName, key, iv, 100 };

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

        out << enc.rdbuf();
    }
    else
    {
        ISymCryptStream<DECRYPT> decrypt{ in, cipherName, key, iv, 100 };
            // comment out the previous line and uncomment the next
            // to use the constructor expecting a string as 1st arg:
//      ISymCryptStream<DECRYPT> decrypt{ argv[2], cipherName, key, 
//                                        iv, 100 };
        out << decrypt.rdbuf();
    }
}
catch (exception const &exc)
{
    cerr << exc.what() << '\n';
}