# Encrypting a hex file

**URL:** <https://community.zymbit.com/t/encrypting-a-hex-file/724>\
**Category:** Encrypting File System\
**Created:** [February 7, 2020, 12:55am UTC](https://community.zymbit.com/t/encrypting-a-hex-file/724 "2020-02-07T00:55:05Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hastich](https://avatars.discourse-cdn.com/v4/letter/h/bc8723/32.png) [@Hastich](https://community.zymbit.com/u/Hastich)\
**Post date:** [February 7, 2020, 12:55am UTC](https://community.zymbit.com/t/encrypting-a-hex-file/724/1 "2020-02-07T00:55:05Z")

</div>

Hello,

I have converted my image to hex and I have zymkey 4i on my raspberry pi. Where can I find your python API for encrypting a hex file? I have the general API documentation but I am not sure which part is related to my question. Any help is appreciated. Thanks

---

<div class="post-metadata">

**Author:** ![Bob\_of\_Zymbit](https://avatars.discourse-cdn.com/v4/letter/b/82dd89/32.png) [@Bob\_of\_Zymbit](https://community.zymbit.com/u/Bob_of_Zymbit)\
**Post date:** [February 8, 2020, 8:24pm UTC](https://community.zymbit.com/t/encrypting-a-hex-file/724/2 "2020-02-08T20:24:23Z")

</div>

The APIs that you are looking for are `lock` and `unlock`. For example:

```auto
import zymkey
import filecmp

zymkey.client.lock("my_plaintext_file", "my_encrypted_file")
zymkey.client.unlock("my_encrypted_file", "my_decrypted_file")

if filecmp.cmp("my_plaintext_file", "my_decrypted_file"):
   print("PASS: original and decrypted files are the same")
else:
   print("FAIL: original and decrypted files differ")

```

Note that it doesn’t matter what the file contents are - hex ascii vs. straight binary is all the same for lock/unlock.

---

<div class="post-metadata">

**Author:** ![Hastich](https://avatars.discourse-cdn.com/v4/letter/h/bc8723/32.png) [@Hastich](https://community.zymbit.com/u/Hastich)\
**Post date:** [February 26, 2020, 10:48pm UTC](https://community.zymbit.com/t/encrypting-a-hex-file/724/3 "2020-02-26T22:48:58Z")

</div>

Thanks Scott I have used those APIs and they work perfectly, however, I was wondering if I encrypt an image and send it to many receivers, if any receiver has a Zymkey4i, can they simply decrypt it back to the original image?  
How can I pass a key to make sure only the trusted receiver can decrypt the file?

---

<div class="post-metadata">

**Author:** ![Bob\_of\_Zymbit](https://avatars.discourse-cdn.com/v4/letter/b/82dd89/32.png) [@Bob\_of\_Zymbit](https://community.zymbit.com/u/Bob_of_Zymbit)\
**Post date:** [February 27, 2020, 4:28pm UTC](https://community.zymbit.com/t/encrypting-a-hex-file/724/4 "2020-02-27T16:28:01Z")

</div>

A file that is locked by a specific zymkey can only be unlocked by that same zymkey. This means that the file could not be decrypted by another zymkey.
