mirror of
https://github.com/gchq/CyberChef.git
synced 2025-04-23 00:06:17 -04:00
Add JWT Verify, Decode and Sign
This commit is contained in:
parent
3905c01a0d
commit
8559f5c8ea
5 changed files with 198 additions and 1 deletions
53
src/core/operations/JWTVerify.mjs
Normal file
53
src/core/operations/JWTVerify.mjs
Normal file
|
@ -0,0 +1,53 @@
|
|||
/**
|
||||
* @author gchq77703 []
|
||||
* @copyright Crown Copyright 2018
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
|
||||
import Operation from "../Operation";
|
||||
import jwt from "jsonwebtoken";
|
||||
|
||||
/**
|
||||
* JWT Verify operation
|
||||
*/
|
||||
class JWTVerify extends Operation {
|
||||
|
||||
/**
|
||||
* JWTVerify constructor
|
||||
*/
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
this.name = "JWT Verify";
|
||||
this.module = "Crypto";
|
||||
this.description = "Verifies that a JSON Web Token is valid and has been signed with the provided secret / private key.";
|
||||
this.infoURL = "https://jwt.io/";
|
||||
this.inputType = "string";
|
||||
this.outputType = "JSON";
|
||||
this.args = [
|
||||
{
|
||||
name: "Private / Secret Key",
|
||||
type: "shortString",
|
||||
value: "secret_cat"
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} input
|
||||
* @param {Object[]} args
|
||||
* @returns {string}
|
||||
*/
|
||||
run(input, args) {
|
||||
const [key] = args;
|
||||
|
||||
try {
|
||||
return jwt.verify(input, key);
|
||||
} catch (err) {
|
||||
return err;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export default JWTVerify;
|
Loading…
Add table
Add a link
Reference in a new issue