constSM4=require('longrise-sm4').sm4letsm4Config={// encrypt/decypt main key; cannot be omittedkey: 'JeF8U9wHFOMfs2Y8',// optional; can be 'cbc' or 'ecb'mode: 'cbc',// default// optional; when use cbc mode, it's necessaryiv: 'UISwD9fW6cFh9SNS',// default is null// optional: this is the cipher data's type; Can be 'base64' or 'text'cipherType: 'base64'// default is base64}letsm4=newSM4(sm4Config)
Encrypt
letplaintext='中国国密加解密算法'letciphertext=sm4.encrypt(plaintext)// ciphertext's result is 'j/+HgSpv8RZQI2YtSq0L1RnemiSokMm1VvLHSTt245U='
Decrypt
letciphertext='j/+HgSpv8RZQI2YtSq0L1RnemiSokMm1VvLHSTt245U='letplaintext=sm4.decrypt(ciphertext)// plaintext's result is '中国国密加解密算法'