π Crypto β
go
import (
"fmt"
"github.com/thuongtruong109/gouse"
)
1. Crypto encode data β
Description: Encode data to base64
Input params: (data []byte)
go
func CryptoEncodeData() {
data := []byte("This is a sample data")
encodedData, err := gouse.EncodeData(data)
if err != nil {
fmt.Println("Error encoding data:", err)
return
}
fmt.Println("Raw data:", string(data))
fmt.Println("Encoded data:", string(encodedData))
}
2. Crypto decode data β
Description: Decode data from base64
Input params: (data []byte)
go
func CryptoDecodeData() {
data := []byte("VGhpcyBpcyBhIHNhbXBsZSBkYXRh")
decodedData, err := gouse.DecodeData(data)
if err != nil {
fmt.Println("Error decoding data:", err)
return
}
fmt.Println("Raw encoded data:", string(data))
fmt.Println("Decoded data:", string(decodedData))
}
3. Crypto encrypt file β
Description: Encrypt data in file
Input params: (filename string, password []byte)
go
func CryptoEncryptFile() {
gouse.EncryptFile("sample.txt", []byte("password"))
println("File content encrypted")
}
4. Crypto decrypt file β
Description: Decrypt data in file
Input params: (filename string, password []byte)
go
func CryptoDecryptFile() {
gouse.DecryptFile("sample.txt", []byte("password"))
println("File content decrypted")
}
5. Crypto encrypt password β
Description: Encrypt password string
Input params: (data string)
go
func CryptoEncryptPassword() {
data := "This is a sample data"
encryptedData, err := gouse.EncryptPassword(data)
if err != nil {
fmt.Println("Error encrypting data:", err)
return
}
fmt.Println("Raw data:", string(data))
fmt.Println("Encrypted data:", string(encryptedData))
}
6. Crypto compare password β
Description: Compare string with the original password
Input params: (data string, password string)
go
func CryptoComparePassword() {
data := "$2a$10$bcA002IOHi5SYHNH4lmIbuHjHplGl7TQZ.MznNrL1N70vAi7ovTa2"
err := gouse.ComparePassword(data, "This is a sample data")
if err != nil {
fmt.Println("Error decrypting data:", err)
return
}
println("Password matched")
}