update Encrypt

This commit is contained in:
Pasha 2024-11-26 15:11:30 +03:00
parent 1695a09815
commit cf56ae1e3f

@ -9,16 +9,12 @@ import (
)
type Encrypt struct {
pubKey string
privKey string
}
func NewEncrypt(pubKey, privKey string) *Encrypt {
return &Encrypt{pubKey: pubKey, privKey: privKey}
PubKey string `env:"ENCRYPT_PUBLIC_KEY"`
PrivKey string `env:"ENCRYPT_PRIVATE_KEY"`
}
func (e *Encrypt) EncryptStr(str string) ([]byte, error) {
block, _ := pem.Decode([]byte(e.pubKey))
block, _ := pem.Decode([]byte(e.PubKey))
if block == nil {
return nil, errors.New("failed to parse PEM block containing the public key")
}
@ -39,7 +35,7 @@ func (e *Encrypt) EncryptStr(str string) ([]byte, error) {
}
func (e *Encrypt) DecryptStr(shifr []byte) (string, error) {
block, _ := pem.Decode([]byte(e.privKey))
block, _ := pem.Decode([]byte(e.PrivKey))
if block == nil {
return "", errors.New("failed to parse PEM block containing the private key")
}