npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

kuncen

v1.0.7

Published

Library untuk token AES-256-CBC dan JWT

Downloads

47

Readme

Kuncen NPM Package

kuncen is an NPM package designed to generate and validate dynamic tokens using AES encryption and expiration time. It provides a secure and efficient way to manage token-based authentication for both backend and frontend applications.

kuncen Logo

Installation

To install this package, use npm or yarn:

npm install kuncen

or

Usage
1. In Express (Backend)
You can use this package in an Express.js application to generate and validate tokens.

Example Code in Express:

const express = require('express');
const { generateToken, validateToken } = require('kuncen');

const app = express();
const key = 'your-secret-key';
const salt = 'your-salt-value';

app.use(express.json());

app.post('/generate-token', (req, res) => {
  const token = generateToken(key, salt, 3); // Token valid for 3 minutes (UTC)
  res.json({ token });
});

app.post('/validate-token', (req, res) => {
  const { token } = req.body;
  const isValid = validateToken(token, key, salt); // Validation without time parameter
  res.json({ valid: isValid });
});

app.listen(3000, () => {
  console.log('Server running on port 3000');
});
  1. In React (Frontend) In a React application, you can use this package to generate tokens before sending requests to the backend.

Example Code in React:

import { generateToken } from 'kuncen';

const key = 'your-secret-key';
const salt = 'your-salt-value';

function sendRequest() {
  const token = generateToken(key, salt, 3); // Token valid for 3 minutes (UTC)

  fetch('http://localhost:3000/validate-token', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    body: JSON.stringify({ token }),
  })
    .then((response) => response.json())
    .then((data) => {
      if (data.valid) {
        console.log('Token is valid');
      } else {
        console.log('Token is not valid');
      }
    });
}

Features generateToken(key, salt, minutes): Generates an AES encrypted token with a combination of key, salt, and expiration time. validateToken(encryptedToken, key, salt): Validates the token based on key, salt, and time. generateJwtToken(key, salt, data, minutes): Generates a JWT token using HS256 with key and salt as the secret. validateJwtToken(token, key, salt): Validates the JWT and returns the payload if valid. encryptPayload(payload, key, salt): Encrypts the payload using AES-256-CBC algorithm. decryptPayload(encryptedPayload, key, salt): Decrypts the encrypted payload using AES-256-CBC algorithm. Explanation of New Features Generate Token Function (Custom AES-256-CBC) This function uses the AES-256-CBC algorithm to encrypt data with the format:

Token Format: IV (hex) : Encrypted DATA (hex) The encrypted data is a combination of key.salt.expiryTime. Validate Token Function (Custom AES-256-CBC) This function decrypts the AES-256-CBC token to check:

Whether the key (key) and salt (salt) match. Whether the token has expired based on expiryTime. Generate JWT Function Generates a JWT token using the combination of key + salt as the secret and the HS256 algorithm.

Supports storing additional payload/data. Expiration time format can be set in minutes, e.g., 10m or 60m. Validate JWT Function Verifies the JWT token to ensure:

The token was created using the correct secret. The token has not expired. If valid, this function returns the payload from the JWT (e.g., { data, iat, exp, ... }).

Encrypt Payload Function (Custom AES-256-CBC) This function encrypts the payload using the AES-256-CBC algorithm with the format:

Encryption Format: IV (hex) : Encrypted DATA (hex) The encrypted data is a JSON string of the payload. Decrypt Payload Function (Custom AES-256-CBC) This function decrypts the encrypted payload using the AES-256-CBC algorithm to check:

Whether the key (key) and salt (salt) match. Returns the original payload as a JSON object. Important Notes Key and Salt Security: Ensure to use secure key and salt values and do not share them with unauthorized parties. Time Synchronization: Ensure the server and client have synchronized time (UTC-based) for accurate token validation.