MCPcopy Create free account
hub / github.com/chanify/chanify / EncryptData

Method EncryptData

model/message.go:249–263  ·  view source on GitHub ↗

EncryptData return encrypted body with key & timestamp

(key []byte, ts uint64)

Source from the content-addressed store, hash-verified

247
248// EncryptData return encrypted body with key & timestamp
249func (m *Message) EncryptData(key []byte, ts uint64) []byte {
250 m.fixChannel()
251
252 aesgcm, _ := NewAESGCM(key)
253 nonce := make([]byte, 12)
254 nonce[0] = 0x01
255 nonce[1] = 0x01
256 nonce[2] = 0x00
257 nonce[3] = 0x08
258 binary.BigEndian.PutUint64(nonce[4:], ts)
259
260 tag := key[32 : 32+32]
261 out := aesgcm.Seal(nil, nonce, m.Marshal(), tag)
262 return append(nonce, out...)
263}
264
265// Marshal return binary data
266func (m *Message) Marshal() []byte {

Callers 1

sendDirectMethod · 0.80

Calls 3

fixChannelMethod · 0.95
MarshalMethod · 0.95
NewAESGCMFunction · 0.85

Tested by

no test coverage detected