@haici/gmsm4
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

国产密码算法-sm4

安装

npm install @haici/gmsm4 --save

使用方法

一、通过 baseKey 获取加密秘钥 key

约定 baseKey 为字符串(长度不限)

import { genKey } from '@haici/gmsm4';

const key = genKey('123456789');

二、使用 ECB 模式加密

key 要求为 32 位十六进制字符串

import sm4,{ genKey } from '@haici/gmsm4';

let text = 'This is 一段明文内容!';
let key = genKey('123456789');

let enData = sm4.encryptWithECB(key,text); //加密
let deData = sm4.encryptWithECB(key,enData); //解密

三、使用 CBC 模式加密

iv 和 key 要求为 32 位十六进制字符串

import sm4, { genKey } from '@haici/gmsm4';

let text = 'This is 一段明文内容!';
let iv = '00000000000000000000000000000000';
let key = genKey('123456789');

let enData = sm4.encryptWithCBC(key,iv,text); //加密
let deData = sm4.decryptWithCBC(key,iv,enData); //解密

Readme

Keywords

Package Sidebar

Install

npm i @haici/gmsm4

Weekly Downloads

1

Version

1.0.1

License

MIT

Unpacked Size

20.4 kB

Total Files

6

Last publish

Collaborators

  • feng_jj
  • gzhc_gaojie
  • wangchun_020
  • yuechen195
  • liuzhe529
  • haici-fe
  • programmer-yang