-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathRSAEncoder.h
65 lines (60 loc) · 1.6 KB
/
RSAEncoder.h
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
63
64
65
#include "DotNetPELib.h"
#include "bigdigits.h"
namespace DotNetPELib {
class ByteArray
{
public:
ByteArray(size_t len) : len_(len), mem_(new Byte[len]) { memset(mem_,0, len_); }
~ByteArray()
{
memset(mem_, 0, len_);
delete[] mem_;
}
Byte *operator()() { return mem_; }
const Byte *operator()() const { return mem_; }
Byte &operator[](size_t pos) { return *(mem_ + pos); }
size_t size() { return len_; }
Byte *begin() { return mem_; }
Byte *end() { return mem_ + len_; }
private:
Byte *mem_;
size_t len_;
};
// format a message hash into PKCS1 format
// assumes SHA-1 hashing
class PKCS1Formatter
{
public:
PKCS1Formatter(const Byte *msg) : msg_(msg) { }
void Calculate(ByteArray &result);
private:
const Byte *msg_;
static Byte DerHeader[];
};
// Manage SNK file & perform RSA signature
class RSAEncoder
{
public:
RSAEncoder() : modulusBits(0), privateExponent(0), publicExponent(0), keyPair(0), modulus(0) { }
virtual ~RSAEncoder() {
if (privateExponent)
memset(privateExponent, 0, 2048);
if (keyPair)
memset(keyPair, 0, 2048);
if (modulus)
memset(modulus, 0, 2048);
delete [] privateExponent;
delete [] keyPair;
delete [] modulus;
}
size_t LoadStrongNameKeys(const std::string & file);
void GetPublicKeyData(Byte *key, size_t *keySize);
void GetStrongNameSignature(Byte *sig, size_t *sigSize, const Byte *hash, size_t hashSize );
//private:
size_t modulusBits;
int publicExponent;
Byte *privateExponent;
Byte *keyPair;
Byte *modulus;
};
}