-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtriple_des.go
More file actions
39 lines (30 loc) · 951 Bytes
/
triple_des.go
File metadata and controls
39 lines (30 loc) · 951 Bytes
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
// Copyright 2024 FishGoddess. All rights reserved.
// Use of this source code is governed by a MIT style
// license that can be found in the LICENSE file.
package main
import (
"bytes"
"fmt"
"github.com/FishGoddess/cryptox/des"
)
func main() {
// As you know, key is necessary in triple des.
// However, not all modes need iv, such as ecb.
key := []byte("123456788765432112345678")
iv := []byte("87654321")
data := []byte("你好,世界")
fmt.Printf("data: %s\n", data)
// Use ctr mode to encrypt data with no padding and encoding base64.
encrypt, err := des.EncryptTripleCTR(data, key, iv, des.WithBase64())
if err != nil {
panic(err)
}
fmt.Printf("encrypt: %s\n", encrypt)
// Decrypt data in the same way.
decrypt, err := des.DecryptTripleCTR(encrypt, key, iv, des.WithBase64())
if err != nil {
panic(err)
}
fmt.Printf("decrypt: %s\n", decrypt)
fmt.Printf("decrypt is right: %+v\n", bytes.Equal(decrypt, data))
}