MCPcopy Create free account
hub / github.com/Hidden-Node/GooseRelayVPN-AndroidClient / NewCryptoFromHexKey

Function NewCryptoFromHexKey

internal/frame/crypto.go:35–52  ·  view source on GitHub ↗

NewCryptoFromHexKey parses a 64-char hex string into a 32-byte AES-256 key and constructs a Crypto. The same key must be configured on both client and VPS server.

(hexKey string)

Source from the content-addressed store, hash-verified

33// NewCryptoFromHexKey parses a 64-char hex string into a 32-byte AES-256 key
34// and constructs a Crypto. The same key must be configured on both client and VPS server.
35func NewCryptoFromHexKey(hexKey string) (*Crypto, error) {
36 key, err := hex.DecodeString(hexKey)
37 if err != nil {
38 return nil, fmt.Errorf("crypto: invalid hex key: %w", err)
39 }
40 if len(key) != 32 {
41 return nil, fmt.Errorf("crypto: key must be 32 bytes (AES-256), got %d", len(key))
42 }
43 block, err := aes.NewCipher(key)
44 if err != nil {
45 return nil, fmt.Errorf("crypto: aes new cipher: %w", err)
46 }
47 gcm, err := cipher.NewGCM(block)
48 if err != nil {
49 return nil, fmt.Errorf("crypto: new gcm: %w", err)
50 }
51 return &Crypto{aead: gcm}, nil
52}
53
54// Seal encrypts plaintext and returns nonce||ciphertext (tag appended by GCM).
55func (c *Crypto) Seal(plaintext []byte) ([]byte, error) {

Calls

no outgoing calls