| 34 | } |
| 35 | |
| 36 | func SealBundle(data []byte, key []byte) ([]byte, error) { |
| 37 | ahead, err := chacha20poly1305.NewX(key[:]) |
| 38 | if err != nil { |
| 39 | return nil, err |
| 40 | } |
| 41 | nonce := make([]byte, chacha20poly1305.NonceSizeX) |
| 42 | _, err = rand.Read(nonce) |
| 43 | if err != nil { |
| 44 | return nil, err |
| 45 | } |
| 46 | cipherText := ahead.Seal(make([]byte, 0), nonce, data, make([]byte, 0)) |
| 47 | return append(nonce, cipherText...), nil |
| 48 | } |
| 49 | |
| 50 | func OpenBundle(data []byte, key []byte) ([]byte, error) { |
| 51 | if len(data) < chacha20poly1305.NonceSizeX { |