mirror of
https://github.com/hatchet-dev/hatchet.git
synced 2025-12-30 21:29:44 -06:00
* 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
32 lines
676 B
Go
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)
|
|
}
|