forked from packetflinger/q2admin
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenkeys.c
More file actions
38 lines (30 loc) · 716 Bytes
/
genkeys.c
File metadata and controls
38 lines (30 loc) · 716 Bytes
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
#include <openssl/rsa.h>
#include <openssl/bn.h>
#include <openssl/pem.h>
void GenerateKeyPair(int bits)
{
FILE *fp;
RSA *rsa;
BIGNUM *e;
time_t seconds;
char filename[64];
time(&seconds);
rsa = RSA_new();
e = BN_new();
BN_set_word(e, RSA_F4);
RSA_generate_key_ex(rsa, bits, e, NULL);
snprintf(filename, sizeof(filename), "public-%d.pem", seconds);
fp = fopen(filename, "wb");
PEM_write_RSAPublicKey(fp, rsa);
fclose(fp);
snprintf(filename, sizeof(filename), "private-%d.pem", seconds);
fp = fopen(filename, "wb");
PEM_write_RSAPrivateKey(fp, rsa, NULL, NULL, 0, NULL, NULL);
fclose(fp);
BN_free(e);
RSA_free(rsa);
}
int main(int argc, char **argv) {
GenerateKeyPair(2048);
return 0;
}