Description
I am Creating Signature From my Java Spring Boot Application but one in a 10-20 times it says Signature is Invalid rest of the times it works fine. Don’t Know the Reason.
Browser Console Error
tp-errors.handler.ts:31 Error intercepted Error: Uncaught (in promise): Object: {“type”:“JOIN_MEETING_FAILED”,“reason”:“Signature is invalid.”,“errorCode”:3712}
at resolvePromise (zone.js:1211:1)
at resolvePromise (zone.js:1165:1)
at zone.js:1118:1
at zone.js:1134:1
at asyncGeneratorStep (asyncToGenerator.js:11:1)
at _throw (asyncToGenerator.js:29:1)
at _ZoneDelegate.invoke (zone.js:372:1)
at Object.onInvoke (core.mjs:25608:33)
at _ZoneDelegate.invoke (zone.js:371:1)
at Zone.run (zone.js:134:1)
h
Which Web Meeting SDK version?
“^2.9.5”
Meeting SDK Signature Generation Code Snippet
public String getZoomSignature() {
String sdkKey = "**********";
String sdkSecret ="*********";
if (sdkKey == null || sdkSecret == null) {
return null;
} else {
long iat = Math.round(new Date().getTime() / (float) 1000) - 30;
long exp = iat + 60 * 60 * 2;
JSONObject header = new JSONObject();
header.put("alg", "HS256");
header.put("typ", "JWT");
JSONObject payload = new JSONObject();
payload.put("sdkKey", sdkKey);
payload.put("mn", id);
payload.put("role", 0);
payload.put("iat", iat);
payload.put("exp", exp);
payload.put("appKey", sdkKey);
payload.put("tokenExp", exp);
final String base64Payload = encode(payload.toString().getBytes(StandardCharsets.UTF_8));
final String base64header = encode(header.toString().getBytes(StandardCharsets.UTF_8));
final String signature = hmacSha256(base64header + "." + base64Payload, sdkSecret);
return base64header + "." + base64Payload + "." + signature;
}
}
public String hmacSha256(String data, String secret) {
try {
byte[] hash = secret.getBytes(StandardCharsets.UTF_8);
Mac sha256Hmac = Mac.getInstance("HmacSHA256");
SecretKeySpec secretKey = new SecretKeySpec(hash, "HmacSHA256");
sha256Hmac.init(secretKey);
byte[] signedBytes = sha256Hmac.doFinal(data.getBytes(StandardCharsets.UTF_8));
return encode(signedBytes);
} catch (NoSuchAlgorithmException | InvalidKeyException ex) {
LOGGER.debug("Error in Zoom Signature Creation \n" + ex.getMessage());
}
return null;
}
public String encode(byte[] bytes) {
return Base64.getUrlEncoder().withoutPadding().encodeToString(bytes);
}
Device (please complete the following information):
- Device: [Macbook Pro, windows]
- OS: [e.g. macOS Ventura, windows 11]
- Browser: [e.g. Chrome]
- Browser Version [e.g. 88.0.4324.150 (Official Build) (x86_64)]