npm install --save sm-crypto
import {sm2,sm3,sm4} from 'sm-crypto'
let keypair = sm2.generateKeyPairHex()
publicKey = keypair.publicKey
privateKey = keypair.privateKey
const compressedPublicKey = sm2.compressPublicKeyHex(publicKey)
sm2.comparePublicKeyHex(publicKey, compressedPublicKey)
const cipherMode = 1
let encryptData = sm2.doEncrypt(msgString, publicKey, cipherMode)
let decryptData = sm2.doDecrypt(encryptData, privateKey, cipherMode)
encryptData = sm2.doEncrypt(msgArray, publicKey, cipherMode)
decryptData = sm2.doDecrypt(encryptData, privateKey, cipherMode, {output: 'array'})
let hashData = sm3('abc')
hashData = sm3('abc', {
key: 'daac25c1512fe50f79b0e4526b93f5c0e1460cef40b6dd44af13caec62e8c60e0d885f3c6d6fb51e530889e6fd4ac743a6d332e68a0f2a3923f42585dceb93e9',
})
const msg = 'hello world! 我是 juneandgreen.'
const key = '0123456789abcdeffedcba9876543210'
let encryptData = sm4.encrypt(msg, key)
let decryptData = sm4.decrypt(encryptData, key)