MCPcopy Create free account
hub / github.com/supabase/auth / NewEncryptedString

Function NewEncryptedString

internal/crypto/crypto.go:148–167  ·  view source on GitHub ↗
(id string, data []byte, keyID string, keyBase64URL string)

Source from the content-addressed store, hash-verified

146}
147
148func NewEncryptedString(id string, data []byte, keyID string, keyBase64URL string) (*EncryptedString, error) {
149 key, err := deriveSymmetricKey(id, keyID, keyBase64URL)
150 if err != nil {
151 return nil, err
152 }
153
154 block := must(aes.NewCipher(key))
155 cipher := must(cipher.NewGCM(block))
156
157 es := EncryptedString{
158 KeyID: keyID,
159 Algorithm: "aes-gcm-hkdf",
160 Nonce: make([]byte, 12),
161 }
162
163 must(io.ReadFull(rand.Reader, es.Nonce))
164 es.Data = cipher.Seal(nil, es.Nonce, data, nil) // #nosec G407
165
166 return &es, nil
167}
168
169// SecureAlphanumeric generates a secure random alphanumeric string using standard library
170func SecureAlphanumeric(length int) string {

Callers 9

verifyTOTPFactorMethod · 0.92
SetClientSecretMethod · 0.92
SetupRefreshTokenDataMethod · 0.92
SetSecretMethod · 0.92
SetPasswordMethod · 0.92
SetOtpCodeMethod · 0.92

Calls 2

deriveSymmetricKeyFunction · 0.85
mustFunction · 0.85

Tested by 2