# Does ipfs takes more time to upload and download encrypted data?

**URL:** <https://discuss.ipfs.tech/t/does-ipfs-takes-more-time-to-upload-and-download-encrypted-data/17856>\
**Category:** Kubo\
**Tags:** go-ipfs, files, use-cases-and-apps\
**Created:** [April 11, 2024, 5:35pm UTC](https://discuss.ipfs.tech/t/does-ipfs-takes-more-time-to-upload-and-download-encrypted-data/17856 "2024-04-11T17:35:15Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![zeeshanhameed12](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ipfs.tech/zeeshanhameed12/32/7205_2.png) [@zeeshanhameed12](https://discuss.ipfs.tech/u/zeeshanhameed12)\
**Post date:** [April 11, 2024, 5:35pm UTC](https://discuss.ipfs.tech/t/does-ipfs-takes-more-time-to-upload-and-download-encrypted-data/17856/1 "2024-04-11T17:35:15Z")

</div>

I am inegrating security features with ipfs. When i try to upload encrypted data, ipfs takes more time perform following operation compared with plain text "  
buffer := bytes.NewBuffer(encryptedShard)  
ipfsHash, err := api.Add(buffer)  
if err != nil {  
log.Fatal(err)  
}" can anyone explain why it takes more time (3x) ? looking for your response

---

<div class="post-metadata">

**Author:** ![Jorropo](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ipfs.tech/jorropo/32/3230_2.png) [@Jorropo](https://discuss.ipfs.tech/u/Jorropo)\
**Post date:** [April 11, 2024, 5:39pm UTC](https://discuss.ipfs.tech/t/does-ipfs-takes-more-time-to-upload-and-download-encrypted-data/17856/2 "2024-04-11T17:39:17Z")

</div>

It would be nice to see a reproduction.  
On the top of my head, it makes no sense and looks like a bug, Kubo does not even parse the content and blindly hash and chunk it.

---

<div class="post-metadata">

**Author:** ![zeeshanhameed12](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ipfs.tech/zeeshanhameed12/32/7205_2.png) [@zeeshanhameed12](https://discuss.ipfs.tech/u/zeeshanhameed12)\
**Post date:** [April 11, 2024, 5:41pm UTC](https://discuss.ipfs.tech/t/does-ipfs-takes-more-time-to-upload-and-download-encrypted-data/17856/3 "2024-04-11T17:41:35Z")

</div>

> [@Jorropo](#):
>
> reproduction

I am using AESGCM encryption. the data size is also the same before and after encryption.

---

<div class="post-metadata">

**Author:** ![Jorropo](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ipfs.tech/jorropo/32/3230_2.png) [@Jorropo](https://discuss.ipfs.tech/u/Jorropo)\
**Post date:** [April 11, 2024, 5:42pm UTC](https://discuss.ipfs.tech/t/does-ipfs-takes-more-time-to-upload-and-download-encrypted-data/17856/4 "2024-04-11T17:42:34Z")

</div>

I mean, could you share a script that shows this behavior ?

---

<div class="post-metadata">

**Author:** ![zeeshanhameed12](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ipfs.tech/zeeshanhameed12/32/7205_2.png) [@zeeshanhameed12](https://discuss.ipfs.tech/u/zeeshanhameed12)\
**Post date:** [April 11, 2024, 6:10pm UTC](https://discuss.ipfs.tech/t/does-ipfs-takes-more-time-to-upload-and-download-encrypted-data/17856/5 "2024-04-11T18:10:16Z")

</div>

```auto
package main

import (
	"bytes"
	"crypto/aes"
	"crypto/cipher"
	"crypto/rand"
	"encoding/hex"
	"fmt"
	"io"
	"io/ioutil"
	"log"
	"time"

	shell "github.com/ipfs/go-ipfs-api"
)

const AESKeyHex = "0b3a29ef29afed5e0ac68f97a96036cedfa8f79a3867bbf6c607d53b07cfd44e" // Private Key for AES

func encodingData(data []byte, AESKey []byte, api *shell.Shell) {

	encryptedShard, err := encrypt(data, AESKey)
	if err != nil {
		fmt.Println("error while encrypting",err)
	}

	encodingTime := time.Now()

	buffer := bytes.NewBuffer(encryptedShard) // please replace encryptedShard with data if you want to upload plain text 
	//start := time.Now()
	ipfsHash, err := api.Add(buffer)
	if err != nil {
		log.Fatal(err)
	}
	Encoding_time := time.Since(encodingTime)
	fmt.Println("data encryption time", Encoding_time)
	fmt.Println("length od plaintext", len(data))
	fmt.Println("length of enrypted text", len(encryptedShard))
	fmt.Println("IPFS hash", ipfsHash)

}

func encrypt(data []byte, key []byte) ([]byte, error) {
	block, err := aes.NewCipher(key)
	if err != nil {
		return nil, err
	}
	gcm, err := cipher.NewGCM(block)
	if err != nil {
		return nil, err
	}
	nonce := make([]byte, gcm.NonceSize())
	if _, err = io.ReadFull(rand.Reader, nonce); err != nil {
		return nil, err
	}
	return gcm.Seal(nonce, nonce, data, nil), nil
}

func main() {
	var filePath string
	api := shell.NewShell("localhost:5001")
	fmt.Println("Enter full path of the file:")
	fmt.Scan(&filePath)
	data, err := ioutil.ReadFile(string(filePath))
	if err != nil {
		panic(err)
	}
	keyBytes, err := hex.DecodeString(AESKeyHex)
	if err != nil {
		fmt.Println("Error decoding key string:", err)
		return
	}
	encodingData(data, keyBytes, api) // Encoding and encrypting the data

}

```

---

<div class="post-metadata">

**Author:** ![Jorropo](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ipfs.tech/jorropo/32/3230_2.png) [@Jorropo](https://discuss.ipfs.tech/u/Jorropo)\
**Post date:** [April 11, 2024, 6:11pm UTC](https://discuss.ipfs.tech/t/does-ipfs-takes-more-time-to-upload-and-download-encrypted-data/17856/6 "2024-04-11T18:11:30Z")

</div>

You can create a codeblock like this:  
```go  
// Code goes there …  
```  
Your code is being interpreted as markdown syntax right now.

Edit: thx, way easier to read.

---

<div class="post-metadata">

**Author:** ![zeeshanhameed12](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ipfs.tech/zeeshanhameed12/32/7205_2.png) [@zeeshanhameed12](https://discuss.ipfs.tech/u/zeeshanhameed12)\
**Post date:** [April 11, 2024, 6:18pm UTC](https://discuss.ipfs.tech/t/does-ipfs-takes-more-time-to-upload-and-download-encrypted-data/17856/7 "2024-04-11T18:18:01Z")

</div>

Dear, You just need to upload any file from your local directory. You can replace replace **encryptedShard** with **data** if you want to upload plain text.

---

<div class="post-metadata">

**Author:** ![zeeshanhameed12](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ipfs.tech/zeeshanhameed12/32/7205_2.png) [@zeeshanhameed12](https://discuss.ipfs.tech/u/zeeshanhameed12)\
**Post date:** [April 12, 2024, 9:19am UTC](https://discuss.ipfs.tech/t/does-ipfs-takes-more-time-to-upload-and-download-encrypted-data/17856/8 "2024-04-12T09:19:55Z")

</div>

@hector can you help

---

<div class="post-metadata">

**Author:** ![hector](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ipfs.tech/hector/32/178_2.png) [@hector](https://discuss.ipfs.tech/u/hector)\
**Post date:** [April 12, 2024, 1:44pm UTC](https://discuss.ipfs.tech/t/does-ipfs-takes-more-time-to-upload-and-download-encrypted-data/17856/9 "2024-04-12T13:44:37Z")

</div>

I don’t think this has anything to do with Kubo per se and that we can offer any light beyond what you would discover yourself with more testing.

Are you running this twice in a row and seeing different encoding times?

Is the data and encrypted data the same size ?

Are you testing in a Kubo instance that is in the same state in both cases? (i.e. offline, empty repo)?

Have you tried adding 100x times and comparing that it is consistent? Restarting Kubo between adds?
