我正在NodeJS上实现JWT承载令牌流,这是我正在尝试的知识库, https://help.salesforce.com/articleView?id=remoteaccess_oauth_jwt_flow.htm&type=5
您可以看到用于构建JWT承载令牌的示例Java代码。它从java密钥库中提取私钥,并对JWT标头和JWT Claims对象进行签名。
//Load the private key from a keystore
KeyStore keystore = KeyStore.getInstance("JKS");
keystore.load(new FileInputStream("./path/to/keystore.jks"), "keystorepassword".toCharArray());
PrivateKey privateKey = (PrivateKey) keystore.getKey("certalias", "privatekeypassword".toCharArray());
//Sign the JWT Header + "." + JWT Claims Object
Signature signature = Signature.getInstance("SHA256withRSA");
signature.initSign(privateKey);
signature.update(token.toString().getBytes("UTF-8"));
String signedPayload = Base64.encodeBase64URLSafeString(signature.sign());
我正在尝试通过使用node-keytool
提取私钥和jwt-js
进行令牌签名的方法在NodeJS上进行相同的操作。看起来node-keytool
无法从密钥库中提取私钥。您能帮我如何在NodeJS上实现上述代码吗?