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 { type Encrypt struct {
pubKey string PubKey string `env:"ENCRYPT_PUBLIC_KEY"`
privKey string PrivKey string `env:"ENCRYPT_PRIVATE_KEY"`
}
func NewEncrypt(pubKey, privKey string) *Encrypt {
return &Encrypt{pubKey: pubKey, privKey: privKey}
} }
func (e *Encrypt) EncryptStr(str string) ([]byte, error) { func (e *Encrypt) EncryptStr(str string) ([]byte, error) {
block, _ := pem.Decode([]byte(e.pubKey)) block, _ := pem.Decode([]byte(e.PubKey))
if block == nil { if block == nil {
return nil, errors.New("failed to parse PEM block containing the public key") 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) { func (e *Encrypt) DecryptStr(shifr []byte) (string, error) {
block, _ := pem.Decode([]byte(e.privKey)) block, _ := pem.Decode([]byte(e.PrivKey))
if block == nil { if block == nil {
return "", errors.New("failed to parse PEM block containing the private key") return "", errors.New("failed to parse PEM block containing the private key")
} }