0
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
package main
import (
"crypto/rand"
"crypto/sha256"
"fmt"
"golang.org/x/crypto/nacl/secretbox"
"seks/sopHex"
)
func ran() []byte {
var b [32]byte
_, err := rand.Reader.Read(b[:])
if err != nil {
panic(err)
}
return b[:]
}
func main() {
passwd := []byte("TestPassword")
encrypted, err := sopHex.UnMarshall(`-----BEGIN SEKS SECRET-----
A+=PEEM3<3PI<++1VE+=VS1O+L+H1AN3
=L3HI+MPM33OE+3NANN1NASNSII=MV+N
1+P3VSOA+SOVLSL3VE=+EHM++LSPEAIM
SLI3NPMPN3IMMP=V<VS1N31AHPHAI1=S
+3P=1ISMIHALS3VHL=V3O3=1V=<1SI1H
E1HH=H3=IVE+OE=H+E=SE<VL1V13SIH=
3AP<OA3O=HNELO3PNL3N+1LO<I3SMOP<
VSEH<HEOIVOHSMLV=HH=3MAO3HMSSSEV
==E3AOO<HPOMSN<PAE1HNVP<NP+AVO+O
3ISIHAP1PE=1VPS<O1S<+LN+H=E3MLV+
-----END SEKS SECRET-----
`)
if err != nil {
fmt.Println(err)
return
}
salt := encrypted[0:32]
hash := sha256.New()
hash.Write(passwd)
hash.Write(salt)
var key [32]byte
copy(key[:], hash.Sum(nil))
deNonce := [24]byte(encrypted[32 : 32+24])
decrypted, boolEnlon := secretbox.Open(nil, encrypted[32+24:], &deNonce, &key)
if boolEnlon != true {
fmt.Println("OOPS")
return
}
fmt.Println(string(decrypted))
}