-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathrsa-sign.cpp
56 lines (50 loc) · 1.4 KB
/
rsa-sign.cpp
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
// https://github.com/rodlie/verifyrsa
// BSD 3-Clause License
#include "verifyrsa.h"
#include <string>
#include <iostream>
#include <fstream>
#include <sstream>
int main(int argc, char* argv[]) {
if (argc<3) {
std::cout << "VerifyRSA - https://github.com/rodlie/verifyrsa" << std::endl;
std::cout << "" << std::endl;
std::cout << "Usage: rsa-sign <private key> <text file>" << std::endl;
return 0;
}
std::string key, plain;
std::ifstream keyFile, textFile;
keyFile.open(argv[1]);
if (keyFile.is_open()) {
std::stringstream ss;
ss << keyFile.rdbuf();
key = ss.str();
keyFile.close();
}
textFile.open(argv[2]);
if (textFile.is_open()) {
std::stringstream ss;
ss << textFile.rdbuf();
plain = ss.str();
textFile.close();
}
if (key.empty() || plain.empty()) {
std::cerr << "Missing key or text." << std::endl;
return 1;
}
char* signature = VerifyRSA::sign(key, plain);
if (sizeof(signature)<1) {
std::cerr << "Unable to sign file!" << std::endl;
return 1;
}
std::ofstream ascFile;
std::string filename = argv[2];
filename.append(".asc");
std::ofstream os(filename.c_str());
if (!os) {
std::cerr << "Failed to write signature!" << std::endl;
return 1;
}
else { os << signature; }
return 0;
}