Skip to content

Commit

Permalink
feat: minor
Browse files Browse the repository at this point in the history
  • Loading branch information
dyaksa committed Nov 26, 2024
1 parent e3e8232 commit c86e618
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions crypto/aesx/aes.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"errors"
"io"

"github.com/dyaksa/encryption-pii/crypto/config"
"github.com/dyaksa/encryption-pii/crypto/core"
)

Expand Down Expand Up @@ -380,9 +379,8 @@ func Decrypt(alg AesAlg, key []byte, encryptedData []byte) ([]byte, error) {
return nil, errors.New("decrypt process failed")
}

func Encrypted(alg AesAlg, plainData string) ([]byte, error) {
aesKey := config.GetAESKey()
block, err := aes.NewCipher([]byte(aesKey))
func Encrypted(alg AesAlg, key string, plainData string) ([]byte, error) {
block, err := aes.NewCipher([]byte(key))
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -441,15 +439,14 @@ func Encrypted(alg AesAlg, plainData string) ([]byte, error) {
return nil, errors.New("encrypt process failed")
}

func Decrypted(alg AesAlg, encryptedData []byte) (string, error) {
aesKey := config.GetAESKey()
func Decrypted(alg AesAlg, key string, encryptedData []byte) (string, error) {
encryptedDataOut := make([]byte, hex.DecodedLen(len(encryptedData)))
encryptedDataOutN, err := hex.Decode(encryptedDataOut, encryptedData)
if err != nil {
return "", err
}

block, err := aes.NewCipher([]byte(aesKey))
block, err := aes.NewCipher([]byte(key))
if err != nil {
return "", err
}
Expand Down

0 comments on commit c86e618

Please sign in to comment.