---
title: Sensitive Information
slug: connect/sensitive-information
docTags: 
createdAt: 2024-04-25T14:54:54.126Z
---

There are many sensitive information In [report product](docId\:xkr8lrggFj7YFng1vaYdD), for example, the `enquiryCpf `present in each reports, and the `cpfNumber` in the [identity](docId\:ItiltmkqBDf_9oAG6biCd) report.

Due to the presence of scenarios where partners require backtracking, we have encoded this using the AES symmetric encryption algorithm. and the encrypted key should be the `secretKey` in the [credentials](docId\:TH0ZSmTaGx57xFHBBG8VW) used by you go on boarding, you can contact Klavi business personnel([crie@klavi.ai](mailto\:crie@klavi.ai)) to create it.

:::hint{type="info"}
Before you use `secretKey`, you must replace all `-` to `blank`, for example:

`key = strings.ReplaceAll(secretKey, "-", "")`

If your `secretKey` is `d41faae9-fccb-46df-8fbe-025b3fe722b9`, then the `key` is `d41faae9fccb46df8fbe025b3fe722b9`
:::

You can refer to the example code below to decode it.

:::CodeblockTabs
```go
package main

import (
	"crypto/aes"
	"crypto/cipher"
	"crypto/rand"
	"encoding/base64"
	"fmt"
	"io"
)

func encrypt(key []byte, text string) (string, error) {
	plaintext := []byte(text)

	block, err := aes.NewCipher(key)
	if err != nil {
		return "", err
	}

	ciphertext := make([]byte, aes.BlockSize+len(plaintext))
	iv := ciphertext[:aes.BlockSize]
	if _, err := io.ReadFull(rand.Reader, iv); err != nil {
		return "", err
	}

	stream := cipher.NewCFBEncrypter(block, iv)
	stream.XORKeyStream(ciphertext[aes.BlockSize:], plaintext)

	return base64.URLEncoding.EncodeToString(ciphertext), nil
}

func decrypt(key []byte, text string) (string, error) {
	ciphertext, err := base64.URLEncoding.DecodeString(text)
	if err != nil {
		return "", err
	}

	block, err := aes.NewCipher(key)
	if err != nil {
		return "", err
	}

	if len(ciphertext) < aes.BlockSize {
		return "", fmt.Errorf("ciphertext too short")
	}

	iv := ciphertext[:aes.BlockSize]
	ciphertext = ciphertext[aes.BlockSize:]

	stream := cipher.NewCFBDecrypter(block, iv)
	stream.XORKeyStream(ciphertext, ciphertext)

	return string(ciphertext), nil
}

func main() {
	secretKey := []byte("d41faae9-fccb-46df-8fbe-025b3fe722b9")
	text := []byte("Hello, World!")

    key = strings.ReplaceAll(secretKey, "-", "")
    //key's value will be "d41faae9fccb46df8fbe025b3fe722b9"
    
	encryptedText, err := encrypt(key, text)
	if err != nil {
		fmt.Println("Error encrypting:", err)
		return
	}
	fmt.Println("Encrypted:", encryptedText)

	decryptedText, err := decrypt(key, encryptedText)
	if err != nil {
		fmt.Println("Error decrypting:", err)
		return
	}
	fmt.Println("Decrypted:", decryptedText)
}

```

```python
from Crypto.Cipher import AES  
from Crypto.Util.Padding import pad, unpad  
  
secretKey = "d41faae9-fccb-46df-8fbe-025b3fe722b9"  
key = bytes.fromhex(secretKey.replace("-", ""))
#key's value will be "d41faae9fccb46df8fbe025b3fe722b9"

cipher = AES.new(key, AES.MODE_CBC)  
  
message = b"This is a secret message."  

padded_message = pad(message, AES.block_size)  
ciphertext = cipher.encrypt(padded_message)  
iv = cipher.iv  
  
decipher = AES.new(key, AES.MODE_CBC, iv=iv)  
decrypted_padded_message = decipher.decrypt(ciphertext)  
decrypted_message = unpad(decrypted_padded_message, AES.block_size)  

print(decrypted_message)
```
:::

