Skip to content
This repository has been archived by the owner on Dec 15, 2020. It is now read-only.

Commit

Permalink
export private key and cert
Browse files Browse the repository at this point in the history
  • Loading branch information
btoews committed Jun 9, 2017
1 parent ef9f62e commit 6f9d0e9
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions SelfSignedCertificate/SelfSignedCertificate.m
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ - (int)generateX509 {
printf("failed to sign cert\n");
return 0;
}

unsigned char *buf = NULL;
unsigned int len = i2d_X509(self->x509, &buf);
printf("Cert: ");
for (int i = 0; i < len; i++) {
printf("%02x", buf[i]);
}
printf("\n");

return 1;
}
Expand Down Expand Up @@ -95,6 +103,19 @@ - (int)generateKeyPair {
EC_KEY_free(ec);
return 0;
}

unsigned char *priv = NULL;
int len = i2d_ECPrivateKey(ec, &priv);
if (len < 0) {
printf("error exporting private key.\n");
return 0;
}

printf("priv: ");
for (int i = 0; i < len; i++) {
printf("%02x", priv[i]);
}
printf("\n");

return 1;
}
Expand Down

0 comments on commit 6f9d0e9

Please sign in to comment.