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

Function DecryptWithKey

walletapi/cipher.go:44–63  ·  view source on GitHub ↗

extract 12 byte nonce from the data and deseal the data

(Key []byte, Data []byte)

Source from the content-addressed store, hash-verified

42
43// extract 12 byte nonce from the data and deseal the data
44func DecryptWithKey(Key []byte, Data []byte) (result []byte, err error) {
45
46 // make sure data is atleast 28 byte, 16 bytes of AEAD cipher and 12 bytes of nonce
47 if len(Data) < 28 {
48 err = fmt.Errorf("Invalid data")
49 return
50 }
51
52 data_without_nonce := Data[0 : len(Data)-chacha20poly1305.NonceSize]
53
54 nonce := Data[len(Data)-chacha20poly1305.NonceSize:]
55
56 cipher, err := chacha20poly1305.New(Key)
57 if err != nil {
58 return
59 }
60
61 return cipher.Open(result[:0], nonce, data_without_nonce, nil) // result buffer should be different
62
63}
64
65// use master keys, everytime required
66func (w *Wallet_Memory) Encrypt(Data []byte) (result []byte, err error) {

Callers 4

Test_AEAD_CipherFunction · 0.85
Check_PasswordMethod · 0.85
DecryptMethod · 0.85

Calls 1

OpenMethod · 0.80

Tested by 1

Test_AEAD_CipherFunction · 0.68