From cf56ae1e3fb2ff16f7be3488e902a9df7dfad3d9 Mon Sep 17 00:00:00 2001 From: Pasha Date: Tue, 26 Nov 2024 15:11:30 +0300 Subject: [PATCH] update Encrypt --- encrypt/encrypted.go | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/encrypt/encrypted.go b/encrypt/encrypted.go index 540c83a..6cfc2c5 100644 --- a/encrypt/encrypted.go +++ b/encrypt/encrypted.go @@ -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") }