all data in encrypted within the storage using this, PERIOD all data has a new nonce, appended to the the data , last 12 bytes
(Key []byte, Data []byte)
| 24 | // all data in encrypted within the storage using this, PERIOD |
| 25 | // all data has a new nonce, appended to the the data , last 12 bytes |
| 26 | func EncryptWithKey(Key []byte, Data []byte) (result []byte, err error) { |
| 27 | nonce := make([]byte, chacha20poly1305.NonceSize, chacha20poly1305.NonceSize) |
| 28 | cipher, err := chacha20poly1305.New(Key) |
| 29 | if err != nil { |
| 30 | return |
| 31 | } |
| 32 | |
| 33 | _, err = rand.Read(nonce) |
| 34 | if err != nil { |
| 35 | return |
| 36 | } |
| 37 | Data = cipher.Seal(Data[:0], nonce, Data, nil) // is this okay |
| 38 | |
| 39 | result = append(Data, nonce...) // append nonce |
| 40 | return |
| 41 | } |
| 42 | |
| 43 | // extract 12 byte nonce from the data and deseal the data |
| 44 | func DecryptWithKey(Key []byte, Data []byte) (result []byte, err error) { |