Files
hatchet/pkg/encryption/encryption.go
abelanger5 7c3ddfca32 feat: api server extensions (#614)
* feat: allow extending the api server

* chore: remove internal packages to pkg

* chore: update db_gen.go

* fix: expose auth

* fix: move logger to pkg

* fix: don't generate gitignore for prisma client

* fix: allow extensions to register their own api spec

* feat: expose pool on server config

* fix: nil pointer exception on empty opts

* fix: run.go file
2024-06-19 09:36:13 -04:00

32 lines
676 B
Go

package encryption
import (
"fmt"
"github.com/tink-crypto/tink-go/tink"
)
func encrypt(key tink.AEAD, plaintext []byte, dataId string) ([]byte, error) {
// validate data id is not empty
if len(dataId) == 0 {
return nil, fmt.Errorf("data id cannot be empty")
}
associatedData := []byte(dataId)
// encrypt the data
return key.Encrypt(plaintext, associatedData)
}
func decrypt(key tink.AEAD, ciphertext []byte, dataId string) ([]byte, error) {
// validate data id is not empty
if len(dataId) == 0 {
return nil, fmt.Errorf("data id cannot be empty")
}
associatedData := []byte(dataId)
// decrypt the data
return key.Decrypt(ciphertext, associatedData)
}