MCPcopy Create free account
hub / github.com/deroproject/derohe / EncryptWithKey

Function EncryptWithKey

walletapi/cipher.go:26–41  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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
26func 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
44func DecryptWithKey(Key []byte, Data []byte) (result []byte, err error) {

Callers 3

Test_AEAD_CipherFunction · 0.85
Save_WalletMethod · 0.85
EncryptMethod · 0.85

Calls 1

ReadMethod · 0.45

Tested by 1

Test_AEAD_CipherFunction · 0.68