github:  https://github.com/JuneAndGreen/sm-crypto


下载后,dist文件夹包含sm2.js,sm3.js,sm4.js

sm2使用示例

<html>
<head>
    <title>sm2 test</title>
    <script src="sm2.js"></script>
    <script>
        // https://www.npmjs.com/package/sm-crypto
        let privateKey = "00afe48b1181cc73af7914363e1ab986aa4041540ac8e887e8eb1874b75a9edc2e";
        let msg = "123456";
        let sigValueHex6 = sm2.doSignature(msg, privateKey, {
            hash: true,
            der: true,
            userId: 'test',
        })
        console.log(sigValueHex6);


        let publicKey = "045101ff59e3e5b25ce549a3b5d20431c8c33afeb4128b94787b9e6acd6c457a87a51ddba7c730057e1340df4e0d07d7846ecfe1dae2279fa5c3898ad78acb9bdd";
        let cipherMode = 0; // 1 - C1C3C2,0 - C1C2C3,默认为1
        let encryptData = sm2.doEncrypt(msg, publicKey, cipherMode)
        console.log('encryptData', encryptData);
    </script>
</head>
</html>