MCPcopy Index your code
hub / github.com/cloudflare/cloudflared / Decrypt

Method Decrypt

token/encrypt.go:68–80  ·  view source on GitHub ↗

Decrypt data that was encrypted using our publicKey. It will use our privateKey and the sender's publicKey to decrypt data is an encrypted buffer of data, mostly like from the Encrypt function. Messages contain the nonce data on the front of the message. senderPublicKey is a base64 encoded version o

(data []byte, senderPublicKey string)

Source from the content-addressed store, hash-verified

66// senderPublicKey is a base64 encoded version of the sender's public key (most likely from the PublicKey function).
67// The return value is the decrypted buffer or an error.
68func (e *Encrypter) Decrypt(data []byte, senderPublicKey string) ([]byte, error) {
69 var decryptNonce [24]byte
70 copy(decryptNonce[:], data[:24]) // we pull the nonce from the front of the actual message.
71 pubKey, err := e.decodePublicKey(senderPublicKey)
72 if err != nil {
73 return nil, err
74 }
75 decrypted, ok := box.Open(nil, data[24:], &decryptNonce, pubKey, e.privateKey)
76 if !ok {
77 return nil, errors.New("failed to decrypt message")
78 }
79 return decrypted, nil
80}
81
82// Encrypt data using our privateKey and the recipient publicKey
83// data is a buffer of data that we would like to encrypt. Messages will have the nonce added to front

Callers 1

RunTransferFunction · 0.95

Calls 1

decodePublicKeyMethod · 0.95

Tested by

no test coverage detected