EncryptData return encrypted body with key & timestamp
(key []byte, ts uint64)
| 247 | |
| 248 | // EncryptData return encrypted body with key & timestamp |
| 249 | func (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 |
| 266 | func (m *Message) Marshal() []byte { |
no test coverage detected