wallet/pkg/locker/types.go
Anton Nesterov b19bf34e5f
[init]
2024-08-31 16:54:43 +02:00

40 lines
797 B
Go

package locker
import (
"os"
"custodial/pkg/crypto"
)
var PUBLIC_KEY = getenv("PUBLIC_KEY", DEFAULT_PUBLIC_KEY)
var PRIVATE_KEY = getenv("PRIVATE_KEY", DEFAULT_PRIVATE_KEY)
var PrivKey crypto.RSAKey = crypto.RSAKey(PRIVATE_KEY)
var PubKey crypto.RSAKey = crypto.RSAKey(PUBLIC_KEY)
type RSABase64Value string
type StringValue string
func (v RSABase64Value) String() string {
return string(v)
}
func (v RSABase64Value) Decrypt() string {
return PrivKey.DecryptToString(v.String())
}
func (v StringValue) String() string {
return string(v)
}
func (v StringValue) Encrypt() RSABase64Value {
return RSABase64Value(PubKey.EncryptToString(v.String()))
}
func getenv(key, defaultValue string) string {
value := os.Getenv(key)
if len(value) == 0 {
return defaultValue
}
return value
}