Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

kscryp

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

kscryp - npm Package Compare versions

Comparing version 1.0.11 to 1.0.12

2

package.json
{
"name": "kscryp",
"version": "1.0.11",
"version": "1.0.12",
"description": "Cryptography package with support for: JWT, RSA, MD5, SHA, Base64, HEX, JSON, Basic",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -6,9 +6,10 @@ const KsDriver = require("../KsDriver");

encode(data, options) {
try{
try {
const jwt = require('jsonwebtoken');
return jwt.sign(data, options?.privateKey || "!ksike!", {
expiresIn: options?.expiresIn || "30m"
expiresIn: options?.expiresIn || 60 * 60
});
}
catch(error){
catch (error) {
this.lib?.log && this.lib.log({ src: "kscryp:JWT:encode", data, error });

@@ -21,6 +22,10 @@ return null;

try {
if (options?.verify === false) {
let tmp = this.unpack(data);
return options?.full ? tmp : tmp?.data;
}
const jwt = require('jsonwebtoken');
return jwt.verify(data, options?.privateKey || "!ksike!", options?.callback);
}
catch(error) {
catch (error) {
this.lib?.log && this.lib.log({ src: "kscryp:JWT:encode", data, error });

@@ -34,3 +39,21 @@ return null;

}
unpack(data) {
try {
if (!data) {
return null;
}
const lst = data.split('.');
return {
head: this.lib.decode(Buffer.from(lst[0], 'base64').toString(), "json"),
data: this.lib.decode(Buffer.from(lst[1], 'base64').toString(), "json"),
code: lst[2]
};
}
catch (error) {
this.lib?.log && this.lib.log({ src: "kscryp:JWT:encode", data, error });
return null;
}
}
}
module.exports = KsJWT;

@@ -40,2 +40,14 @@ const KsCryp = require('../');

});
it("unpack", (done) => {
const jwtStr = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1lIjoidGVzdDEiLCJpYXQiOjE2OTIyOTg2OTYsImV4cCI6MTY5MjMwMDQ5Nn0.XACLhB1ggc1wvEQxt6JQBuCaP9djw7OO8e85A7L9TzM";
const jwtObj = KsCryp.decode(jwtStr, "jwt", { verify: false });
expect(jwtObj).toBeInstanceOf(Object);
expect(jwtObj.name).toBe("test1");
expect(jwtObj.exp).toBe(1692300496);
expect(jwtObj.iat).toBe(1692298696);
done();
});
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc