37 lines
810 B
Go
37 lines
810 B
Go
package lib
|
|
|
|
import (
|
|
"os"
|
|
)
|
|
|
|
func EncryptFile(content []byte, destPath string) error {
|
|
encrypted := CryptoEncryptBytes(content)
|
|
if err := os.WriteFile(destPath, encrypted, 0644); err != nil {
|
|
SendErrorForAnalysis("EncryptFile", err, map[string]interface{}{
|
|
"path": destPath,
|
|
"size": len(content),
|
|
})
|
|
return err
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func DecryptFile(srcPath string) ([]byte, error) {
|
|
encrypted, err := os.ReadFile(srcPath)
|
|
if err != nil {
|
|
SendErrorForAnalysis("DecryptFile.Read", err, map[string]interface{}{
|
|
"path": srcPath,
|
|
})
|
|
return nil, err
|
|
}
|
|
decrypted, err := CryptoDecryptBytes(encrypted)
|
|
if err != nil {
|
|
SendErrorForAnalysis("DecryptFile.Decrypt", err, map[string]interface{}{
|
|
"path": srcPath,
|
|
"size": len(encrypted),
|
|
})
|
|
return nil, err
|
|
}
|
|
return decrypted, nil
|
|
}
|