我将JWT CPP lib用于ARMV7上的嵌入式项目。
到目前为止,这是我的代码:
applypatch-msg.sample, post-update.sample, pre-commit.sample, pre-rebase.sample, prepare-commit-msg.sample, commit-msg.sample, pre-applypatch.sample, pre-push.sample, pre-receive.sample, update.sample
当我创建RS256Validator对象时,程序崩溃并出现以下错误:
错误:0906D06C:LIB(9):函数(109):原因(108)
经过一些研究,我发现它与 // Reading the private key file
std::ifstream ifs("config/rsa_private.pem");
std::string key((std::istreambuf_iterator<char>(ifs)),
(std::istreambuf_iterator<char>()));
std::cout << key.c_str() << std::endl;
// Validate private key with RS256 encryption
RS256Validator signer(key.c_str());
// About expiration time
std::time_t iat = std::time(nullptr);
std::tm expiration_date = *std::localtime(&iat);
expiration_date.tm_year += 1;
std::time_t exp = mktime(&expiration_date);
// Creating the json payload that expires 1 year from today
json_ptr json(json_pack("iat", iat, "exp", exp, "aud", CLOUD_PROJECT_ID));
// Let's encode the token to a char[]
_jwt.reset(JWT::Encode(&signer, json.get()));
std::cout << "GENERATED TOKEN:" << _jwt.get() << std::endl;
有关,并且主要是参数(密钥)无效。我应该给私钥而不是公钥,它似乎完全有效,所以我不明白为什么它不起作用。
嵌入式主板是MangOH Green运行的Legato。