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 🙏

© 2024 – Pkg Stats / Ryan Hefner

sm4js

v0.0.6

Published

An implementation of the browser and nodejs-server side of the sm4 algorithm

Downloads

271

Readme

sm4js

An implementation of the browser and server side of the sm4 algorithm

install

With npm do:

npm install sm4js 

For use in web browsers do:

<script src="base64-js.min.js"></script>
<script src="sm4js.min.js"></script>

config

sm4js has four configuration parameters, key, mode,cipherType and iv.

  • key -encrypt/decypt main key;A string of length 12;
  • mode -optional; can be 'cbc' or 'ecb';default ecb;
  • iv -optional; when use cbc mode, it's necessary;default is null;
  • cipherType - optional; this is the cipher data's type; Can be 'base64' or 'text';default is base64;

methods

sm4js has tow exposed functions, encrypt and decrypt, which both take a single argument.

  • encrypt:Takes a json string and returns a base64 string;
  • decrypt:Takes a base64 string and returns a json string;

compatibility

This plugin is native to ie10+ and you should add polyfill if you want to be compatible with ie9; like this:

<script src="typearray.js"></script>
<script src="base64-js.min.js"></script>
<script src="sm4js.min.js"></script>

useage

import Sm4js from 'sm4js'; //esmodule
const Sm4js = require('sm4js');//commonjs
var sm4Config = {
    key: 'JeF8U9wHFOMfs2Y8',
    mode: 'ecb', 
    iv: 'UISwD9fW6cFh9SNS', 
    cipherType: 'base64' 
}
var sm4 = new Sm4js(sm4Config);
var plaintext = '{"records":[["31","129501868966","1","80.00","6","激进型","20191226","20211225","1","自然人客户风险承受能力问卷","01235","1","3.0","20200623","","-1"]],"columns":["SURVEY_SN","USER_CODE","USER_ROLE","SURVEY_SCORE","RATING_LVL","RATING_LVL_NAME","RATING_DATE","EXP_DATE","SURVEY_CLS","SURVEY_NAME","SURVEY_SYN","ORDINAL","VERSION","NEXT_RATING_DATE","REMARK","SURVEY_USABLE_NUM"]}'
var ciphertext = sm4.encrypt(plaintext);
console.log(ciphertext);
var plaintext1 = sm4.decrypt(ciphertext);
console.log(plaintext1);
//MziAMkwaKe2o+IS5G0TCl3zaRhY3F6YydrQl0cWBQTouvY6mk9fEINoJEGGX/EHdMf2z3DeuBa+ZOYaMfisJ0dr9s6RtI0PRTyWmMnQS0ajVKf7P7yrm64Wliam+t3x7KMx0EMSlnUrr7aE9vEGmECbMKEom5SUjoOsqtyQV29NCg5U71xnM5X3q6O69AzQuoKyzgd4Y2fm54ybTIvIoctHkNefZJ8L8DZm2pVk5iJOByu6dowuME+LeRHR5wjxzTPmVFGLUSBYSR/c+mZd1ndOhi4U7IWFNqXjwa8kNSMTK/lF9fhhxUEAL9P7VllPbQs3OxuYB7h6owZP6egs/BukfRpCp2mgd1HAbQbjeaDA2HVn/0RMPiB0vcU2BQrL0XEj7zVoiJsNew3oO7VAxlqv50Uj16ki4ZAB13A8oazNqA2SMR2il9+d8+N7jUJA+uN06cbM9/X8xUZs37L96O8J32QPDpKJUig1ka/u8py05dUZ9iKNTymoiyun9BGAptJt2xk/sxuP/JTbAllQUhg==
//{"records":[["31","129501868966","1","80.00","6","激进型","20191226","20211225","1","自然人客户风险承受能力问卷","01235","1","3.0","20200623","","-1"]],"columns":["SURVEY_SN","USER_CODE","USER_ROLE","SURVEY_SCORE","RATING_LVL","RATING_LVL_NAME","RATING_DATE","EXP_DATE","SURVEY_CLS","SURVEY_NAME","SURVEY_SYN","ORDINAL","VERSION","NEXT_RATING_DATE","REMARK","SURVEY_USABLE_NUM"]}

license

MIT