Looking at the source code for nodejs (in particular, this file https://github.com/nodejs/node/blob/master/src/node_crypto.cc )
the error is caused by this function
// Takes .pfx or .p12 and password in string or buffer format void SecureContext::LoadPKCS12(const FunctionCallbackInfo<Value>& args) { Environment* env = Environment::GetCurrent(args); ...
At line 964
in = LoadBIO(env, args[0]); if (in == nullptr) { return env->ThrowError("Unable to load BIO"); }
If LoadBIO returns null
// Takes a string or buffer and loads it into a BIO. // Caller responsible for BIO_free_all-ing the returned object. static BIO* LoadBIO(Environment* env, Local<Value> v) { HandleScope scope(env->isolate()); if (v->IsString()) { const node::Utf8Value s(env->isolate(), v); return NodeBIO::NewFixed(*s, s.length()); } if (Buffer::HasInstance(v)) { return NodeBIO::NewFixed(Buffer::Data(v), Buffer::Length(v)); } return nullptr; }
Perhaps the buffer is somehow not readable? It also seems that the function is expecting a utf-8 encoded string.
Some ideas:
Are you sure the path to the file is correct?
Maybe there is a problem with the encoding? Have you tried explicitly setting the encoding fs.readFileSync() ?
Try using fs.readFile(<filename>, <encoding>, function(error, data){}) to see if this causes an error?
source share