提交 80e855dd 编写于 作者: B baiy 提交者: ninecents

支持国密算法 sm2 sm3 #23

上级 685abd6c
......@@ -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)
> 当然项目中还使用很多不知道姓名的大神的代码, 在这里就不一一感谢
......
......@@ -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",
......
{
"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",
......
......@@ -8,12 +8,19 @@
</Select>
</FormItem>
<FormItem>
<Input v-model="current.password" placeholder="密码"></Input>
<Input v-model="current.password" placeholder="密码/秘钥"></Input>
</FormItem>
<FormItem v-if="current.type === 'SM2'">
<Select v-model="current.sm2CipherMode" style="width:100px">
<Option value="C1C3C2">C1C3C2</Option>
<Option value="C1C2C3">C1C2C3</Option>
</Select>
</FormItem>
<FormItem>
<ButtonGroup>
<Button type="primary" @click="handle('encrypt')">加密</Button>
<Button type="primary" @click="handle('decrypt')">解密</Button>
<Button type="primary" @click="sm2Generate()" v-if="current.type === 'SM2'">生成密钥对</Button>
</ButtonGroup>
</FormItem>
</option-block>
......@@ -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"],
}
},
}
......
......@@ -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"]
}
},
}
......
<template>
<div>11</div>
</template>
<script>
export default {
name: "smCrypto",
created () {
const sm2 = require('sm-crypto').sm2
console.log(sm2.generateKeyPairHex())
}
}
</script>
<style scoped>
</style>
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册