From 80e855dd0f9d7bd571fc08f45fbae15605157b2c Mon Sep 17 00:00:00 2001 From: baiy Date: Thu, 10 Sep 2020 17:06:50 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=8C=81=E5=9B=BD=E5=AF=86=E7=AE=97?= =?UTF-8?q?=E6=B3=95=20sm2=20sm3=20#23?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 5 ++-- package-lock.json | 15 +++++++++++ package.json | 3 ++- src/views/tool/encrypt.vue | 50 ++++++++++++++++++++++++++++++++++--- src/views/tool/hash.vue | 5 +++- src/views/tool/smCrypto.vue | 17 +++++++++++++ 6 files changed, 88 insertions(+), 7 deletions(-) create mode 100644 src/views/tool/smCrypto.vue diff --git a/README.md b/README.md index 075ed93..fa8abdc 100644 --- a/README.md +++ b/README.md @@ -11,8 +11,8 @@ ## 功能列表 |功能|说明|离线使用| |---|---|---| -|哈希|`md5`, `sha1`, `sha256`, `sha512`|√| -|加密/解密|`AES`,`DES`,`RC4`,`Rabbit`,`TripleDes`|√| +|哈希|`md5`, `sha1`, `sha256`, `sha512`,`sm3`|√| +|加密/解密|`AES`,`DES`,`RC4`,`Rabbit`,`TripleDes`,`sm2`|√| |BASE64编码|`加密`,`解密`|√| |URL编码|`编码`,`解码`|√| |时间戳|双向转换|√| @@ -63,6 +63,7 @@ - [pconline](http://whois.pconline.com.cn/) - [moment](https://momentjs.com/) - [vue-codemirror](https://www.npmjs.com/package/vue-codemirror) +- [sm-crypto](https://github.com/JuneAndGreen/sm-crypto) > 当然项目中还使用很多不知道姓名的大神的代码, 在这里就不一一感谢 diff --git a/package-lock.json b/package-lock.json index c202501..47c9f53 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11540,6 +11540,21 @@ "is-fullwidth-code-point": "^2.0.0" } }, + "sm-crypto": { + "version": "0.1.4", + "resolved": "https://registry.npmjs.org/sm-crypto/-/sm-crypto-0.1.4.tgz", + "integrity": "sha512-zAu1lvSZNAqkR3B/gdfI4WRUPCHtr5joFd/jzouz1bEkYtH9pi/44YaYWerjlDZi6llZBoFs7MRPP7YEVtKPjw==", + "requires": { + "jsbn": "^1.1.0" + }, + "dependencies": { + "jsbn": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/jsbn/-/jsbn-1.1.0.tgz", + "integrity": "sha1-sBMHyym2GKHtJux56RH4A8TaAEA=" + } + } + }, "snapdragon": { "version": "0.8.2", "resolved": "http://registry.npm.taobao.org/snapdragon/download/snapdragon-0.8.2.tgz", diff --git a/package.json b/package.json index 415ade2..e620506 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "c-tool", - "version": "1.1.0", + "version": "1.2.0", "private": true, "scripts": { "serve": "vue-cli-service serve --port 8081", @@ -30,6 +30,7 @@ "query-string": "^6.13.1", "radix.js": "0.0.1", "serialize-php": "^1.1.2", + "sm-crypto": "^0.1.4", "system": "^2.0.1", "view-design": "^4.3.2", "vue": "^2.6.12", diff --git a/src/views/tool/encrypt.vue b/src/views/tool/encrypt.vue index 49724e6..f1cd657 100644 --- a/src/views/tool/encrypt.vue +++ b/src/views/tool/encrypt.vue @@ -8,12 +8,19 @@ - + + + + + @@ -28,6 +35,7 @@ }, methods: { handle(v) { + const sm2 = require('sm-crypto').sm2 if (this.current.input) { switch (this.current.type) { case "AES": @@ -48,6 +56,22 @@ ).toString(crypto.enc.Utf8); } break; + case "SM2": + if (v === "encrypt") { + this.current.output =sm2.doEncrypt( + this.current.input, + this.current.password, + this.current.sm2CipherMode + ); + } + else{ + this.current.output =sm2.doDecrypt( + this.current.input, + this.current.password, + this.current.sm2CipherMode + ); + } + break; default: return; } @@ -55,18 +79,38 @@ this.$clipboardCopy(this.current.output); this.$saveToolData(this.current); } - } + }, + sm2Generate(){ + const sm2 = require('sm-crypto').sm2 + let keypair = sm2.generateKeyPairHex() + let string = "公钥:\n"+keypair.publicKey+"\n"+"私钥:\n"+keypair.privateKey+"\n\n"+ + "请及时保存秘钥对, 关闭对话框后无法恢复当前秘钥数据" + this.$Modal.info({ + render: (h) => { + return h('Input', { + props: { + value: string, + type:"textarea", + rows:9 + } + }) + }, + okText:"关闭", + width:600 + }) + }, }, data() { return { current:{ input: "", password:"", + sm2CipherMode:"C1C3C2", output: "", type:"AES", operation:"" }, - type: ["AES","DES","RC4","Rabbit","TripleDes"], + type: ["AES","DES","RC4","Rabbit","TripleDes","SM2"], } }, } diff --git a/src/views/tool/hash.vue b/src/views/tool/hash.vue index 5d69ac1..4bebb5a 100644 --- a/src/views/tool/hash.vue +++ b/src/views/tool/hash.vue @@ -33,6 +33,9 @@ case "sha512": this.current.output = crypto.SHA512(this.current.input).toString(); break; + case "sm3": + this.current.output = require('sm-crypto').sm3(this.current.input); + break; default: return; } @@ -49,7 +52,7 @@ output: "", operation:"" }, - type: ['md5', 'sha1', 'sha256', 'sha512'] + type: ['md5', 'sha1', 'sha256', 'sha512',"sm3"] } }, } diff --git a/src/views/tool/smCrypto.vue b/src/views/tool/smCrypto.vue new file mode 100644 index 0000000..8ba7404 --- /dev/null +++ b/src/views/tool/smCrypto.vue @@ -0,0 +1,17 @@ + + + + + \ No newline at end of file -- GitLab