Skip to content

Commit 6607b5e

Browse files
author
lizl6
committed
增加base64编码/解码
1 parent 9a7d886 commit 6607b5e

File tree

5 files changed

+67
-8
lines changed

5 files changed

+67
-8
lines changed

README.md

+7-3
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@
1010

1111
- [x] 中文/UTF-8互转
1212

13+
- [x] Base64编码/解码
14+
1315
- [ ] AES/DES加解密
1416

1517
- [ ] MD5、SHA加密
1618

17-
- [ ] Base64编码/解码
18-
1919
# 开发
2020

2121
```bash
@@ -32,7 +32,7 @@ Bootstrap5终于不再需要jquery了,可以和Vue一起用:
3232

3333
```bash
3434
npm i -D electron
35-
npm i vue bootstrap @popperjs/core
35+
npm i vue bootstrap @popperjs/core crypto-js
3636
```
3737

3838
# 发行版打包
@@ -58,6 +58,10 @@ npm run build-dist:win
5858

5959
![image-20220913162817293](https://imgbd.r-xnoro.com//image-20220913162817293.png)
6060

61+
## Base64编码/解码
62+
63+
![image-20220913170027407](https://imgbd.r-xnoro.com//image-20220913170027407.png)
64+
6165
## 随机数/密码生成器
6266

6367
![image-20220913152551500](https://imgbd.r-xnoro.com//image-20220913152551500.png)

package.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "coderbox",
3-
"version": "1.0.5",
3+
"version": "1.0.6",
44
"description": "基于electron的跨平台的程序员小工具集",
55
"main": "main.js",
66
"scripts": {
@@ -30,7 +30,8 @@
3030
"keywords": [
3131
"coderbox",
3232
"加密",
33-
"编码"
33+
"编码",
34+
"base64"
3435
],
3536
"author": "lizl6",
3637
"license": "Apache-2.0",
@@ -40,6 +41,7 @@
4041
"dependencies": {
4142
"@popperjs/core": "^2.11.6",
4243
"bootstrap": "^5.2.0",
44+
"crypto-js": "^4.1.1",
4345
"vue": "^3.2.38"
4446
}
4547
}

src/component/base64.html

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<link rel="stylesheet" href="../index.css">
2+
<link rel="stylesheet" href="../../node_modules/bootstrap/dist/css/bootstrap.min.css">
3+
<div class="container-fluid" id="app">
4+
<div class="card bg-light text-gray">
5+
<div class="card-head text-muted">Base64编码/解码</div>
6+
</div>
7+
<div class="row pt-2">
8+
<div class="col-1 text-end">原文:</div>
9+
<div class="col"><textarea class="form-control" style="resize:none;" v-model="strNative" cols="30" rows="10"></textarea></div>
10+
</div>
11+
<div class="row mt-3">
12+
<div class="col-1"></div>
13+
<div class="col">
14+
<button type="button" class="btn btn-primary" @click="encode">Base64编码⇩</button>
15+
<button type="button" class="btn btn-primary" style="margin-left:15px;" @click="decode">Base64解码⇧</button>
16+
</div>
17+
</div>
18+
<div class="row mt-3">
19+
<div class="col-1 text-end text-nowrap">密文:</div>
20+
<div class="col"><textarea class="form-control" style="resize:none;" v-model="strCypher" cols="30" rows="10"></textarea></div>
21+
</div>
22+
</div>
23+
<script src="../../node_modules/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
24+
<script src="../../node_modules/crypto-js/crypto-js.js"></script>
25+
<script src="../../node_modules/vue/dist/vue.global.prod.js"></script>
26+
<script>
27+
const app = {
28+
data() {
29+
return {
30+
strNative: '',
31+
strCypher: ''
32+
}
33+
},
34+
methods: {
35+
encode() {
36+
if(this.strNative == '') return;
37+
let str = CryptoJS.enc.Utf8.parse(this.strNative);
38+
this.strCypher = CryptoJS.enc.Base64.stringify(str);
39+
},
40+
decode() {
41+
if(this.strCypher == '') return;
42+
let words = CryptoJS.enc.Base64.parse(this.strCypher);
43+
this.strNative = words.toString(CryptoJS.enc.Utf8);
44+
}
45+
}
46+
}
47+
Vue.createApp(app).mount('#app');
48+
</script>

src/index.html

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121
<div class="dropdown-menu">
2222
<a href="#" class="dropdown-item" @click="to('ascii')">中文/ASCii互转</a>
2323
<a href="#" class="dropdown-item" @click="to('utf8')">中文/UTF-8互转</a>
24-
<a href="#" class="dropdown-item">Base64编码/解码</a>
25-
<a href="#" class="dropdown-item">MD5、SHA加密</a>
26-
<a href="#" class="dropdown-item">AES/DES加解密</a>
24+
<a href="#" class="dropdown-item" @click="to('base64')">Base64编码/解码</a>
25+
<!-- <a href="#" class="dropdown-item">散列/哈希加密</a>
26+
<a href="#" class="dropdown-item">AES/DES加解密</a> -->
2727
</div>
2828
</li>
2929
<li class="nav-item">

src/index.js

+5
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ const app = {
2121
name: 'utf8',
2222
path: './component/utf8.html',
2323
state: 0
24+
},
25+
{
26+
name: 'base64',
27+
path: './component/base64.html',
28+
state: 0
2429
}
2530
],
2631
dataPwd: {

0 commit comments

Comments
 (0)