Giter VIP home page Giter VIP logo

smencrypt's Introduction

js国密加密算法使用说明

# 引入js
<script src="/smEncrypt.min.js"></script>

# 使用
const privateKey = ''
const encry =''
const publicKey = ''
// cipherMode默认0,为0时可不传
const cipherMode = 0

// sm2 加解密 密文04开头
const encode = smEncrypt.sm2Encrypt('测试', publicKey)
const decode = smEncrypt.sm2Decrypt(encry, privateKey)

// sm2 加解密 密文非04开头 
// 公钥私钥都必须转换成小写
const encode2 = smEncrypt.sm2.doEncrypt('测试', publicKey, cipherMode)
const decode2 = smEncrypt.sm2.doDecrypt(encode2, privateKey, cipherMode)

// sm3 加密
var sm3 = smEncrypt.sm3('sm3 test')

console.log(`sm2加密:${encode}`)
console.log(`sm2解密:${decode}`)
console.log(`sm3加密: ${sm3}`)
  • 注意smEncrypt提供2个sm2方法,一种是开头有04的一种是没有04的,这也是为什么许多js版本加密后后台解析不出来的原因
  • smEncrypt.min.js基于sm-crypto,感谢作者

smencrypt's People

Contributors

44021987 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.