-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathsignmessage.cpp
51 lines (38 loc) · 1.09 KB
/
signmessage.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
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
#include "util.h"
#include "base58.h"
bool fTestNet = false;
const string strMessageMagic = "Bitcoin Signed Message:\n"; // from main.cpp
int main(int argc, char *argv[]) {
if (argc != 3) {
fprintf(stderr,
"signmessage <base58privatekey> <message>\n\n"
"Sign a message using a Bitcoin private key.\n");
return 255;
}
string strSecret = argv[1];
string strMessage = argv[2];
CBitcoinSecret vchSecret;
bool fGood = vchSecret.SetString(strSecret);
if (!fGood) {
printf("Private key is not good\n");
return 1;
}
CKey key;
bool fCompressed;
CSecret csecret = vchSecret.GetSecret(fCompressed);
key.SetSecret(csecret, fCompressed);
CHashWriter ss(0);
ss << strMessageMagic;
ss << strMessage;
vector<unsigned char> vchSig;
if (!key.SignCompact(ss.GetHash(), vchSig)) {
printf("Sign failed\n");
return 1;
}
printf("%s\n", EncodeBase64(&vchSig[0], vchSig.size()).c_str());
return 0;
}