1
0
mirror of https://github.com/schollz/cowyo.git synced 2023-08-10 21:13:00 +03:00
cowyo/encrypt/encrypt.go

29 lines
648 B
Go
Raw Permalink Normal View History

package encrypt
import (
"crypto/sha256"
"encoding/hex"
"github.com/schollz/cryptopasta"
)
func EncryptString(toEncrypt string, password string) (string, error) {
key := sha256.Sum256([]byte(password))
encrypted, err := cryptopasta.Encrypt([]byte(toEncrypt), &key)
if err != nil {
return "", err
}
return hex.EncodeToString(encrypted), nil
}
func DecryptString(toDecrypt string, password string) (string, error) {
key := sha256.Sum256([]byte(password))
contentData, err := hex.DecodeString(toDecrypt)
if err != nil {
return "", err
}
bDecrypted, err := cryptopasta.Decrypt(contentData, &key)
return string(bDecrypted), err
}