【发布时间】:2015-03-04 03:00:32
【问题描述】:
我尝试在iojs插件中加载RSA私钥的代码sn-p。
void IojsAddon::New(const FunctionCallbackInfo<Value>& args) {
Isolate* isolate = Isolate::GetCurrent();
HandleScope scope(isolate);
if (args.IsConstructCall()) {
EVP_PKEY* ca_key;
BIO* keyb = BIO_new(BIO_s_file());
BIO_read_filename(keyb, "/path/to/key.pem");
ca_key = PEM_read_bio_PrivateKey(keyb, nullptr, nullptr, nullptr);
std::cout << "type: " << ca_key->type << std::endl; // type: 6
std::cout << "check: " << RSA_check_key(ca_key->pkey.rsa) << std::endl; // check: -1
RSA_print_fp(stdout, ca_key->pkey.rsa, 0); // Segmentation fault: 11
IojsAddon* addon = new IojsAddon();
addon->Wrap(args.This());
args.GetReturnValue().Set(args.This());
} else {
const int argc = 1;
Local<Value> argv[argc] = { args[0] };
Local<Function> cons = Local<Function>::New(isolate, constructor);
args.GetReturnValue().Set(cons->NewInstance(argc, argv));
}
}
在独立应用程序中成功加载 RSA 私钥的代码 sn-p 与前面完全相同。
int main(int argc, char **argv) {
EVP_PKEY* ca_key;
BIO* keyb = BIO_new(BIO_s_file());
BIO_read_filename(keyb, "/path/to/key.pem");
ca_key = PEM_read_bio_PrivateKey(keyb, nullptr, nullptr, nullptr);
std::cout << "type: " << ca_key->type << std::endl; // type: 6
std::cout << "check: " << RSA_check_key(ca_key->pkey.rsa) << std::endl; // check: -1
RSA_print_fp(stdout, ca_key->pkey.rsa, 0); // print out the key info successfully.
return (0);
}
附言
- iojs: v1.2.0
- pangyp:v2.0.1
我在这里错过了什么?任何帮助将不胜感激!
【问题讨论】: