# Encrypting & decrypting sensor data on disk using Zymkey

**URL:** <https://community.zymbit.com/t/encrypting-decrypting-sensor-data-on-disk-using-zymkey/94>\
**Category:** ZYMKEY4\
**Created:** [December 13, 2016, 10:02pm UTC](https://community.zymbit.com/t/encrypting-decrypting-sensor-data-on-disk-using-zymkey/94 "2016-12-13T22:02:15Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![evan](https://avatars.discourse-cdn.com/v4/letter/e/54ee81/32.png) [@evan](https://community.zymbit.com/u/evan)\
**Post date:** [December 13, 2016, 10:02pm UTC](https://community.zymbit.com/t/encrypting-decrypting-sensor-data-on-disk-using-zymkey/94/1 "2016-12-13T22:02:15Z")

</div>

See [Zymbit’s Documentation Site](https://docs.zymbit.com/tutorials/sensor-data/) for the most recent AWS documentation.

---

<div class="post-metadata">

**Author:** ![abhishekrjadutta](https://avatars.discourse-cdn.com/v4/letter/a/c2a13f/32.png) [@abhishekrjadutta](https://community.zymbit.com/u/abhishekrjadutta)\
**Post date:** [April 21, 2018, 10:19pm UTC](https://community.zymbit.com/t/encrypting-decrypting-sensor-data-on-disk-using-zymkey/94/2 "2018-04-21T22:19:27Z")

</div>

Hello! I was trying to use the zymkey.client.lock() function on a Raspberry Pi 3 running Raspbian jessie with the Zymkey 4 i module. However, every time I try to tun tre function, it returns an error “Assertionerror: bad return code -1”. This happens regardless of me using a bytearray or a basestring filename as input. Any idea why this could be happening?

---

<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:** [April 25, 2018, 4:24pm UTC](https://community.zymbit.com/t/encrypting-decrypting-sensor-data-on-disk-using-zymkey/94/3 "2018-04-25T16:24:07Z")

</div>

Can you please tell me what `sudo systemctl zkifc` shows?  
Also, can you post the entire python exception trace?

---

<div class="post-metadata">

**Author:** ![abhishekrjadutta](https://avatars.discourse-cdn.com/v4/letter/a/c2a13f/32.png) [@abhishekrjadutta](https://community.zymbit.com/u/abhishekrjadutta)\
**Post date:** [April 25, 2018, 4:48pm UTC](https://community.zymbit.com/t/encrypting-decrypting-sensor-data-on-disk-using-zymkey/94/4 "2018-04-25T16:48:00Z")

</div>

Hi Scott,

The systemctl command returns " unknown operation ‘zkifc’ ". Seems weird although I can use the zymkey for functions like controlling the led.

if I run " zymkey.client.lock(bytearray(“hello”,‘utf8’)) " the exception trace reads:

Traceback (most recent call last):  
File “”, line 1, in   
File “/usr/local/lib/python2.7/dist-packages/zymkey/module.py”, line 196, in lock  
raise AssertionError(‘bad return code {!r}’.format(ret))  
AssertionError: bad return code -1

Another thing I observed yesterday was when running the zk\_crypto\_test file. If i generate a signature with one string and I try to verify that signature with another string, it should have given false but it gives a true value and the program exits when it reaches the line  
" raise Exception(‘verification should have failed, but passed’) "

---

<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:** [April 25, 2018, 5:02pm UTC](https://community.zymbit.com/t/encrypting-decrypting-sensor-data-on-disk-using-zymkey/94/5 "2018-04-25T17:02:59Z")

</div>

I forgot something in the systemctl command: `sudo systemctl status zkifc`. Please run this and post.

If you are able to control the LED, it seems to me that you the python module might be out of sync with the zymkey daemon (zkifc).

At this point, I would recommend purging the zymkey software and reinstalling it.

---

<div class="post-metadata">

**Author:** ![abhishekrjadutta](https://avatars.discourse-cdn.com/v4/letter/a/c2a13f/32.png) [@abhishekrjadutta](https://community.zymbit.com/u/abhishekrjadutta)\
**Post date:** [April 25, 2018, 5:15pm UTC](https://community.zymbit.com/t/encrypting-decrypting-sensor-data-on-disk-using-zymkey/94/6 "2018-04-25T17:15:02Z")

</div>

This is the output of systemctl:

zkifc.service - Zymkey Interface Connector  
Loaded: loaded (/etc/systemd/system/zkifc.service; enabled)  
Active: active (running) since Wed 2018-04-25 16:36:13 UTC; 37min ago  
Process: 653 ExecStartPre=/bin/bash -c mkdir -p {BASE\_DIR} && chown -R zymbit.zymbit {BASE\_DIR} (code=exited, status=0/SUCCESS)  
Main PID: 659 (su)  
CGroup: /system.slice/zkifc.service  
‣ 659 /bin/su zymbit -s /bin/bash -c zkifc -s /var/lib/zymbit/

Apr 25 16:36:13 raspberrypi systemd[1]: Starting Zymkey Interface Connector…  
Apr 25 16:36:13 raspberrypi systemd[1]: Started Zymkey Interface Connector.  
Apr 25 16:36:13 raspberrypi su[659]: Successful su for zymbit by root  
Apr 25 16:36:13 raspberrypi su[659]: + ??? root:zymbit  
Apr 25 16:36:13 raspberrypi su[659]: pam\_unix(su:session): session opened for user zymbit by (uid=0)

Sure, I will try reinstalling it and see if helps!

---

<div class="post-metadata">

**Author:** ![abhishekrjadutta](https://avatars.discourse-cdn.com/v4/letter/a/c2a13f/32.png) [@abhishekrjadutta](https://community.zymbit.com/u/abhishekrjadutta)\
**Post date:** [April 25, 2018, 5:33pm UTC](https://community.zymbit.com/t/encrypting-decrypting-sensor-data-on-disk-using-zymkey/94/7 "2018-04-25T17:33:50Z")

</div>

i tried reinstalling the software but to no avail. The same error persists.

---

<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:** [April 26, 2018, 2:28pm UTC](https://community.zymbit.com/t/encrypting-decrypting-sensor-data-on-disk-using-zymkey/94/8 "2018-04-26T14:28:18Z")

</div>

When you reinstalled, did you perform a purge of the old zymkey software?  
`sudo apt-get purge zkifc libzk`  
`sudo pip uninstall zku`

Please run the above commands and then rerun the install script.

---

<div class="post-metadata">

**Author:** ![abhishekrjadutta](https://avatars.discourse-cdn.com/v4/letter/a/c2a13f/32.png) [@abhishekrjadutta](https://community.zymbit.com/u/abhishekrjadutta)\
**Post date:** [April 26, 2018, 4:05pm UTC](https://community.zymbit.com/t/encrypting-decrypting-sensor-data-on-disk-using-zymkey/94/9 "2018-04-26T16:05:06Z")

</div>

Hey scott! Thanks for the instructions! I think it works now!!

---

<div class="post-metadata">

**Author:** ![crvinay1992](https://avatars.discourse-cdn.com/v4/letter/c/ecc23a/32.png) [@crvinay1992](https://community.zymbit.com/u/crvinay1992)\
**Post date:** [February 27, 2019, 8:40am UTC](https://community.zymbit.com/t/encrypting-decrypting-sensor-data-on-disk-using-zymkey/94/10 "2019-02-27T08:40:54Z")

</div>

Is it possible to use the shared key to encrypt and send the data via MQTT to another raspberry pi device and then decrypt it?

---

<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, 2019, 6:27pm UTC](https://community.zymbit.com/t/encrypting-decrypting-sensor-data-on-disk-using-zymkey/94/11 "2019-02-27T18:27:13Z")

</div>

Hi @crvinay1992,

The lock and unlock operations can only be used local to the zymkey because all private keys are unique to the zymkey and not exportable to the outside world. However, you definitely could sign data packages between the sender and receiver.

---

<div class="post-metadata">

**Author:** ![crvinay1992](https://avatars.discourse-cdn.com/v4/letter/c/ecc23a/32.png) [@crvinay1992](https://community.zymbit.com/u/crvinay1992)\
**Post date:** [February 27, 2019, 9:54pm UTC](https://community.zymbit.com/t/encrypting-decrypting-sensor-data-on-disk-using-zymkey/94/12 "2019-02-27T21:54:03Z")

</div>

> [@Bob\_of\_Zymbit](#):
>
> The lock and unlock operations can only be used local to the zymkey because all private keys are unique to the zymkey and not exportable to the outside world. However, you definitely could sign data packages between the sender and receiver.

Yes, I want to use the priv-pub key pair to create and store a secret key and use it for symmetric encryption between two raspberry pi’s with zymbits paired to them. I read on another thread that there is a solution based on the zymkey toolchain to achieve this. Can I have more details on this please?

Link to the thread: [Same Encryption key for 2 Zymkeys - #4 by vivekb](https://community.zymbit.com/t/same-encryption-key-for-2-zymkeys/115/4)

---

<div class="post-metadata">

**Author:** ![Michelle\_of\_Zymbit](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michelle\_of\_Zymbit](https://community.zymbit.com/u/Michelle_of_Zymbit)\
**Post date:** [August 25, 2021, 4:56pm UTC](https://community.zymbit.com/t/encrypting-decrypting-sensor-data-on-disk-using-zymkey/94/13 "2021-08-25T16:56:36Z")

</div>


