Skip to content

Instantly share code, notes, and snippets.

@devendranaga
Created February 14, 2019 05:53
Show Gist options
  • Save devendranaga/58df06084a8763463ebc8f89124fe259 to your computer and use it in GitHub Desktop.
Save devendranaga/58df06084a8763463ebc8f89124fe259 to your computer and use it in GitHub Desktop.
int load_privkey(std::string privkey)
{
FILE *fp;
fp = fopen(privkey.c_str(), "r");
if (!fp) {
return -1;
}
privatekey = PEM_read_ECPrivateKey(fp, NULL, NULL, NULL);
if (!privatekey) {
ERR_print_errors_fp(stderr);
return -1;
}
// validate the key
EC_KEY_check_key(privatekey);
evp_sign_key = EVP_PKEY_new();
int ret;
ret = EVP_PKEY_assign_EC_KEY(evp_sign_key, privatekey);
if (ret != 1) {
ERR_print_errors_fp(stderr);
return -1;
}
fclose(fp);
std::cout << "privkey load ok" << std::endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment