-
Notifications
You must be signed in to change notification settings - Fork 69
/
Copy pathencrypter.go
60 lines (49 loc) · 1.39 KB
/
encrypter.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
package dongle
type Encrypter struct {
dongle
}
// newEncrypter returns a new Encrypter instance.
func newEncrypter() Encrypter {
return Encrypter{}
}
// FromString encrypts from string.
func (e Encrypter) FromString(s string) Encrypter {
e.src = string2bytes(s)
return e
}
// FromBytes encrypts from byte slice.
func (e Encrypter) FromBytes(b []byte) Encrypter {
e.src = b
return e
}
// String implements Stringer interface for Encrypter struct.
func (e Encrypter) String() string {
return e.ToRawString()
}
// ToRawString outputs as raw string without encoding.
func (e Encrypter) ToRawString() string {
return bytes2string(e.dst)
}
// ToHexString outputs as string with hex encoding.
func (e Encrypter) ToHexString() string {
return Encode.FromBytes(e.dst).ByHex().ToString()
}
// ToBase64String outputs as string with base64 encoding.
func (e Encrypter) ToBase64String() string {
return Encode.FromBytes(e.dst).ByBase64().ToString()
}
// ToRawBytes outputs as raw byte slice without encoding.
func (e Encrypter) ToRawBytes() []byte {
if len(e.dst) == 0 {
return []byte("")
}
return e.dst
}
// ToHexBytes outputs as byte with hex encoding.
func (e Encrypter) ToHexBytes() []byte {
return Encode.FromBytes(e.dst).ByHex().ToBytes()
}
// ToBase64Bytes outputs as byte slice with base64 encoding.
func (e Encrypter) ToBase64Bytes() []byte {
return Encode.FromBytes(e.dst).ByBase64().ToBytes()
}