-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrender_text_encrypt.go
193 lines (152 loc) · 3.92 KB
/
render_text_encrypt.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
package main
import (
"encoding/base64"
"sync"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/dialog"
"fyne.io/fyne/v2/layout"
"fyne.io/fyne/v2/theme"
"fyne.io/fyne/v2/widget"
"github.com/aixoio/aixoio-privacy-tools/lib/aes"
"github.com/aixoio/aixoio-privacy-tools/lib/asconhelper"
"github.com/aixoio/aixoio-privacy-tools/lib/hashing"
)
func render_text_encrypt(w fyne.Window) fyne.CanvasObject {
backbtn := widget.NewButtonWithIcon("Back to menu", theme.NavigateBackIcon(), func() { w.SetContent(render_text(w)) })
pwd_wid := widget.NewPasswordEntry()
opts := []string{"AES-256 Bit GCM with SHA256", "AES-256 Bit CBC with SHA256", "Ascon 128-bit with SHA256 truncated", "Ascon80pq 160-bit with SHA256 truncated"}
sel_wid := widget.NewSelect(opts, func(s string) {})
sel_wid.SetSelectedIndex(0)
msg_in := widget.NewMultiLineEntry()
msg_in.Wrapping = fyne.TextWrapBreak
actbtn := widget.NewButton("Encrypt", func() {
switch sel_wid.SelectedIndex() {
case 0: // GCM
pwd_hash := hashing.Sha256_to_bytes([]byte(pwd_wid.Text))
var wg sync.WaitGroup
wg.Add(1)
var out []byte
var err error
go func() {
defer wg.Done()
out, err = aes.AesGCMEncrypt(pwd_hash, []byte(msg_in.Text))
}()
d := dialog.NewCustomWithoutButtons("Encrypting - Your message", container.NewPadded(
widget.NewProgressBarInfinite(),
), w)
d.Show()
wg.Wait()
d.Hide()
if err != nil {
show_err(w, err)
return
}
out_str := base64.StdEncoding.EncodeToString(out)
msg_in.SetText(out_str)
case 1: // CBC
pwd_hash := hashing.Sha256_to_bytes([]byte(pwd_wid.Text))
var wg sync.WaitGroup
wg.Add(1)
var out []byte
var err error
go func() {
defer wg.Done()
out, err = aes.AesCBCEncrypt(pwd_hash, []byte(msg_in.Text))
}()
d := dialog.NewCustomWithoutButtons("Encrypting - Your message", container.NewPadded(
widget.NewProgressBarInfinite(),
), w)
d.Show()
wg.Wait()
d.Hide()
if err != nil {
show_err(w, err)
return
}
out_str := base64.StdEncoding.EncodeToString(out)
msg_in.SetText(out_str)
case 2: // Ascon
pwd_hash := hashing.Sha256_to_bytes_128bit([]byte(pwd_wid.Text))
var wg sync.WaitGroup
wg.Add(1)
var out []byte
var err error
go func() {
defer wg.Done()
out, err = asconhelper.AsconEncrypt(pwd_hash, []byte(msg_in.Text))
}()
d := dialog.NewCustomWithoutButtons("Encrypting - Your message", container.NewPadded(
widget.NewProgressBarInfinite(),
), w)
d.Show()
wg.Wait()
d.Hide()
if err != nil {
show_err(w, err)
return
}
out_str := base64.StdEncoding.EncodeToString(out)
msg_in.SetText(out_str)
case 3: // Ascon80pq
pwd_hash := hashing.Sha256_to_bytes_160bit([]byte(pwd_wid.Text))
var wg sync.WaitGroup
wg.Add(1)
var out []byte
var err error
go func() {
defer wg.Done()
out, err = asconhelper.AsconEncrypt(pwd_hash, []byte(msg_in.Text))
}()
d := dialog.NewCustomWithoutButtons("Encrypting - Your message", container.NewPadded(
widget.NewProgressBarInfinite(),
), w)
d.Show()
wg.Wait()
d.Hide()
if err != nil {
show_err(w, err)
return
}
out_str := base64.StdEncoding.EncodeToString(out)
msg_in.SetText(out_str)
}
})
actbtn.Disable()
msg_in.OnChanged = func(s string) {
if len(s) != 0 && len(pwd_wid.Text) != 0 {
actbtn.Enable()
} else {
actbtn.Disable()
}
}
pwd_wid.OnChanged = func(s string) {
if len(s) != 0 && len(msg_in.Text) != 0 {
actbtn.Enable()
} else {
actbtn.Disable()
}
}
return container.NewBorder(
container.NewGridWithColumns(
3,
backbtn,
widget.NewLabel("Text - Encrypt"),
widget.NewLabel(""),
),
actbtn,
nil,
nil,
container.NewPadded(
container.New(
layout.NewFormLayout(),
widget.NewLabel("Password"),
pwd_wid,
widget.NewLabel("Cipher"),
sel_wid,
widget.NewLabel("Message"),
msg_in,
),
),
)
}