-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go.bak
92 lines (71 loc) · 2.66 KB
/
main.go.bak
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
package main
import (
"fmt"
"github.com/tuhin37/goutil/fileio"
)
// func encrypt(data, key []byte) ([]byte, error) {
// block, err := aes.NewCipher(key)
// if err != nil {
// return nil, err
// }
// // Generate a random initialization vector (IV)
// iv := make([]byte, aes.BlockSize)
// _, err = io.ReadFull(rand.Reader, iv)
// if err != nil {
// return nil, err
// }
// // Pad the data to the nearest multiple of the block size
// padding := aes.BlockSize - (len(data) % aes.BlockSize)
// paddedData := append(data, bytes.Repeat([]byte{byte(padding)}, padding)...)
// // Create a new CBC mode encrypter using the AES block cipher
// mode := cipher.NewCBCEncrypter(block, iv)
// // Create a buffer for the encrypted data
// encrypted := make([]byte, len(paddedData))
// // Encrypt the data
// mode.CryptBlocks(encrypted, paddedData)
// // Prepend the IV to the encrypted data
// encrypted = append(iv, encrypted...)
// // Encode the encrypted data as base64 for readability
// encoded := make([]byte, base64.StdEncoding.EncodedLen(len(encrypted)))
// base64.StdEncoding.Encode(encoded, encrypted)
// return encoded, nil
// }
// func decrypt(encrypted, key []byte) ([]byte, error) {
// block, err := aes.NewCipher(key)
// if err != nil {
// return nil, err
// }
// // Decode the base64-encoded encrypted data
// decoded := make([]byte, base64.StdEncoding.DecodedLen(len(encrypted)))
// n, err := base64.StdEncoding.Decode(decoded, encrypted)
// if err != nil {
// return nil, err
// }
// decoded = decoded[:n]
// // Extract the IV from the encrypted data
// iv := decoded[:aes.BlockSize]
// encryptedData := decoded[aes.BlockSize:]
// // Create a new CBC mode decrypter using the AES block cipher
// mode := cipher.NewCBCDecrypter(block, iv)
// // Create a buffer for the decrypted data
// decrypted := make([]byte, len(encryptedData))
// // Decrypt the data
// mode.CryptBlocks(decrypted, encryptedData)
// // Remove the padding from the decrypted data
// padding := int(decrypted[len(decrypted)-1])
// unpadded := decrypted[:len(decrypted)-padding]
// return unpadded, nil
// }
func main() {
// Example usage
file := fileio.FileHandler("./foo.bar")
fileContentRaw := file.ReadBinary()
fmt.Println("md5: ", fileContentRaw.CalculateMD5())
fmt.Println("sha1: ", fileContentRaw.CalculateSHA1())
fmt.Println("sha256: ", fileContentRaw.CalculateSHA256())
fmt.Println("sha512: ", fileContentRaw.CalculateSHA512())
fmt.Println("sha3: ", fileContentRaw.CalculateSHA3())
fmt.Println("bcrypt: ", fileContentRaw.CalculateBcrypt())
fmt.Println("crc32: ", fileContentRaw.CalculateCRC32())
fmt.Println("Adler32: ", fileContentRaw.CalculateAdler32())
}