# Decrypt single .md file

**URL:** <https://discourse.joplinapp.org/t/decrypt-single-md-file/640>\
**Category:** Support\
**Created:** [12 September 2018 10:12 UTC](https://discourse.joplinapp.org/t/decrypt-single-md-file/640 "2018-09-12T10:12:44Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![maxmopp](https://yyz2.discourse-cdn.com/flex028/user_avatar/discourse.joplinapp.org/maxmopp/32/238_2.png) [@maxmopp](https://discourse.joplinapp.org/u/maxmopp)\
**Post date:** [12 September 2018 10:12 UTC](https://discourse.joplinapp.org/t/decrypt-single-md-file/640/1 "2018-09-12T10:12:44Z")

</div>

I sync Android - Ubuntu via Nextcloud and use encryption.  
In one of my notes I included a jpg, which was encrypted (same key) as well. Whatever went wrong the encrypted jpg got lost while syncing. I know the name (e5edcb5f0dcc48a49498cb00d2362a3c.md) and restored it from a backup. The reference in the editor is still there, but the link in the db is probably lost:

- how can I reimport the (encrypted) file to Joplin
- is there any option to decrypt a file outside Joplin

---

<div class="post-metadata">

**Author:** ![laurent](https://avatars.discourse-cdn.com/v4/letter/l/ce7236/32.png) [@laurent](https://discourse.joplinapp.org/u/laurent)\
**Post date:** [12 September 2018 13:20 UTC](https://discourse.joplinapp.org/t/decrypt-single-md-file/640/2 "2018-09-12T13:20:40Z")

</div>

On the sync target, is the JPEG file that matches e5edcb5f0dcc48a49498cb00d2362a3c.md still in the .resource folder? If so, I would just add the .md file on the sync target, then sync from the device and it should pick up the file.

---

<div class="post-metadata">

**Author:** ![maxmopp](https://yyz2.discourse-cdn.com/flex028/user_avatar/discourse.joplinapp.org/maxmopp/32/238_2.png) [@maxmopp](https://discourse.joplinapp.org/u/maxmopp)\
**Post date:** [12 September 2018 13:47 UTC](https://discourse.joplinapp.org/t/decrypt-single-md-file/640/3 "2018-09-12T13:47:34Z")

</div>

That was my problem: the file was in the .resource folder, was not attached to the note. Tried restarting Joplin several times.  
Is there any way to decrypt from the linux shell?

---

<div class="post-metadata">

**Author:** ![laurent](https://avatars.discourse-cdn.com/v4/letter/l/ce7236/32.png) [@laurent](https://discourse.joplinapp.org/u/laurent)\
**Post date:** [12 September 2018 15:40 UTC](https://discourse.joplinapp.org/t/decrypt-single-md-file/640/4 "2018-09-12T15:40:52Z")

</div>

e5edcb5f0dcc48a49498cb00d2362a3c.md as well as .resource/e5edcb5f0dcc48a49498cb00d2362a3c are on the sync target?

If so, the issue is that they are not being decyrpted on your computer? or not being synced?

If not being synced, how do you know that’s the case? Did you open the SQLite database to confirm?

You can use `joplin e2ee decryption <path>` to decrypt a file but I’m not sure if this is what you need in this case

---

<div class="post-metadata">

**Author:** ![maxmopp](https://yyz2.discourse-cdn.com/flex028/user_avatar/discourse.joplinapp.org/maxmopp/32/238_2.png) [@maxmopp](https://discourse.joplinapp.org/u/maxmopp)\
**Post date:** [13 September 2018 13:07 UTC](https://discourse.joplinapp.org/t/decrypt-single-md-file/640/5 "2018-09-13T13:07:35Z")

</div>

Sorry for my late response, I did not want to seem too stupid, although I am still not wiser  
I did look into the db, selected select \* from notes where title like ‘%title%’; e5edcb5f0dcc48a49498cb00d2362a3c in the body, and then could not find  
select \* from notes where id like ‘e5edcb5f0dcc48a49498cb00d2362a3c%’;  
I seem to have issues with the jopin e2ee as well:

joplin e2ee decrypt -v 007c0991648345409fce8ae3cf3a79db.md  
Invalid encryption identifier. Data is not actually encrypted? ID was: 007c0

joplin e2ee status -v 007c0991648345409fce8ae3cf3a79db.md  
Encryption is: Enabled

---

<div class="post-metadata">

**Author:** ![laurent](https://avatars.discourse-cdn.com/v4/letter/l/ce7236/32.png) [@laurent](https://discourse.joplinapp.org/u/laurent)\
**Post date:** [13 September 2018 16:30 UTC](https://discourse.joplinapp.org/t/decrypt-single-md-file/640/6 "2018-09-13T16:30:26Z")

</div>

As e5edc is an image (a resource) you would need to check in the `resources` table:

```
select * from resources where id = 'e5edcb5f0dcc48a49498cb00d2362a3c';

```

If you want to check if this resource is used in a note, you could use this query:

```
select * from notes where body like '%e5edcb5f0dcc48a49498cb00d2362a3c%';

```

Do any of these queries bring up anything?

Next could you check in ~/.config/joplin-desktop/resources if the file e5edcb5f0dcc48a49498cb00d2362a3c.jpg is there?

I don’t quite understand your decrypt query as you mentioned one ID (e5edcb5…) but you try to decrypt another (007c09…). If it says “Data is not actually encrypted?” maybe it’s indeed not encrypted. You can verify this by opening the .md file and check the encryption\_applied field. It will be “1” if the data is actually encrypted.

---

<div class="post-metadata">

**Author:** ![maxmopp](https://yyz2.discourse-cdn.com/flex028/user_avatar/discourse.joplinapp.org/maxmopp/32/238_2.png) [@maxmopp](https://discourse.joplinapp.org/u/maxmopp)\
**Post date:** [15 September 2018 12:45 UTC](https://discourse.joplinapp.org/t/decrypt-single-md-file/640/7 "2018-09-15T12:45:59Z")

</div>

Thanks a lot for your effort and info!

cat 007c0991648345409fce8ae3cf3a79db.md  
…  
encryption\_applied: 1  
I understand it should be encrypted?

I blamed the nextcloud sync for loosing the encrypted jpg and had a nonencrypted version of theat jpg still and added that as a new jpg to the note. I changed my sync to “File System” and included it in my unison sync which I trust in for all my devices.

I will try to pull the old db and files from the zfs snapshot and try your the checks you recommend

---

<div class="post-metadata">

**Author:** ![maxmopp](https://yyz2.discourse-cdn.com/flex028/user_avatar/discourse.joplinapp.org/maxmopp/32/238_2.png) [@maxmopp](https://discourse.joplinapp.org/u/maxmopp)\
**Post date:** [15 September 2018 13:03 UTC](https://discourse.joplinapp.org/t/decrypt-single-md-file/640/8 "2018-09-15T13:03:03Z")

</div>

Now I looked into the data from Sep 12:

The only thing in ~/.config/joplin-desktop/resources is: /e5edcb5f0dcc48a49498cb00d2362a3c.crypted

select \* from resources where id = ‘e5edcb5f0dcc48a49498cb00d2362a3c’;  
delivers no match

select \* from resources where id = ‘e5edcb5f0dcc48a49498cb00d2362a3c’;  
matches with id 5b54fdc5b9714821b8f525044f06c6f8 (I assume the note?) and a parent id (Notebook?)  
and body:  
`![Nusstrudel.jpg.jpg](:/e5edcb5f0dcc48a49498cb00d2362a3c)`

the double jpg extension is because of my mistake specifying the filename converting a pdf to a jpg (the pdf seems to not be supported on Android yet)

---

<div class="post-metadata">

**Author:** ![maxmopp](https://yyz2.discourse-cdn.com/flex028/user_avatar/discourse.joplinapp.org/maxmopp/32/238_2.png) [@maxmopp](https://discourse.joplinapp.org/u/maxmopp)\
**Post date:** [15 September 2018 13:08 UTC](https://discourse.joplinapp.org/t/decrypt-single-md-file/640/9 "2018-09-15T13:08:00Z")

</div>

Regarding `joplin e2ee decryption <path>`:  
I would be really happy to be able to use that, as it would be very helpfull to track encrypted synchronized files when I am not certain how well my sync worked or I end up with files that seem to belong nowhere  
I really like Joplin and use it for (to me) important stuff

---

<div class="post-metadata">

**Author:** ![zblesk](https://yyz2.discourse-cdn.com/flex028/user_avatar/discourse.joplinapp.org/zblesk/32/11_2.png) [@zblesk](https://discourse.joplinapp.org/u/zblesk)\
**Post date:** [23 October 2018 08:27 UTC](https://discourse.joplinapp.org/t/decrypt-single-md-file/640/10 "2018-10-23T08:27:09Z")

</div>

I have a potentially related issue: I had a note with a few images in it. Yesterday I’ve noticed that across all of my synced devices, all but the last of the images has disappeared.

The note text is unchanged and looks like this: `![aa7c55ceb39b23d58da6512be3d36efe.png](:/3669f9eaa3aa4ef589c94974a42f91f8)`

If I search my hard drive for `3669f9eaa3aa4ef589c94974a42f91f8`, I can only find a `3669f9eaa3aa4ef589c94974a42f91f8.crypted` file in my `.config\joplin-desktop\resources` folder.

How could this happen? (I am now using the PC I’ve added the pictures on, so it’s not that it just hasn’t decrypted yet. The note is weeks old and the sync process has finished several times today, so I don’t think anything’s waiting for decryption.

Should I try the `joplin e2ee decryption` method? (I don’t even have the terminal version of the app installed yet.)  
Is there any way to find out whether _other_ resources were affected? I haven’t discovered any other discrepancies by randomly clicking around, but am quite anxious about the possibility of losing something else.

---

<div class="post-metadata">

**Author:** ![laurent](https://avatars.discourse-cdn.com/v4/letter/l/ce7236/32.png) [@laurent](https://discourse.joplinapp.org/u/laurent)\
**Post date:** [23 October 2018 23:16 UTC](https://discourse.joplinapp.org/t/decrypt-single-md-file/640/11 "2018-10-23T23:16:21Z")

</div>

How old is the note? For a short time there was a bug that would incorrectly delete resources of new notes so just wondering if that’s your issue.

If needed you can indeed recover the image using the e2ee command as long as you still have your master key.

---

<div class="post-metadata">

**Author:** ![zblesk](https://yyz2.discourse-cdn.com/flex028/user_avatar/discourse.joplinapp.org/zblesk/32/11_2.png) [@zblesk](https://discourse.joplinapp.org/u/zblesk)\
**Post date:** [25 October 2018 11:16 UTC](https://discourse.joplinapp.org/t/decrypt-single-md-file/640/12 "2018-10-25T11:16:26Z")

</div>

It was created in the middle of September, IIRC.  
Thanks, I'll try that when I get the CLI version working. (So far I only got some weird npm and permission errors. 😃 I'll look into it.)

---

<div class="post-metadata">

**Author:** ![maxmopp](https://yyz2.discourse-cdn.com/flex028/user_avatar/discourse.joplinapp.org/maxmopp/32/238_2.png) [@maxmopp](https://discourse.joplinapp.org/u/maxmopp)\
**Post date:** [22 December 2018 10:24 UTC](https://discourse.joplinapp.org/t/decrypt-single-md-file/640/13 "2018-12-22T10:24:14Z")

</div>

Laurent, I am very sorry to pick up that thread again: I do not get the single md decryption:

I have one file in a directory:  
cat 60642171cb734bde8fcd4f6dca03ed05.md  
&nbsp;&nbsp;&nbsp;&nbsp;…  
&nbsp;&nbsp;&nbsp;&nbsp;encryption\_cipher\_text: JED01000022017e41ef181afc47deb70c3d78a0f3ebab000386{  
&nbsp;&nbsp;&nbsp;&nbsp;…

seems to be encrypted

e2ee status:  
$ joplin e2ee -v target-status ./  
Encrypted items: 1/1  
Encrypted resources: 0/0  
Other items (never encrypted): 0

# Encrypted paths

.[//60642171cb734bde8fcd4f6dca03ed05.md](https://60642171cb734bde8fcd4f6dca03ed05.md)

# Decrypted paths

$ joplin e2ee decrypt 60642171cb734bde8fcd4f6dca03ed05.md  
Invalid encryption identifier. Data is not actually encrypted? ID was: 60642

target-status is the same.I assume I do something very basic wrong but cannot find a solution. Can you please clarify?

---

<div class="post-metadata">

**Author:** ![zblesk](https://yyz2.discourse-cdn.com/flex028/user_avatar/discourse.joplinapp.org/zblesk/32/11_2.png) [@zblesk](https://discourse.joplinapp.org/u/zblesk)\
**Post date:** [4 March 2019 22:44 UTC](https://discourse.joplinapp.org/t/decrypt-single-md-file/640/14 "2019-03-04T22:44:23Z")

</div>

I know this is an old thread, but once again I'm trying to get my lost resources back.

So after trying a few things, these are my findings.  
My naive attempt - to `joplin export` and check if the file is in the exported dir - didn't work. 😃

My lost files are mostly .png images. They probably really _are_ encrypted, i've tried just renaming the .crypted file to .png, but it isn't a valid file.

(Aside: there are several mentions of `joplin e2ee dectpytion`. Seems to me the actual command is `joplin e2ee decrypt`, and Joplin does not give any complaint when you put in the wrong one.)

So I've tried (under WSL):

```auto
> joplin e2ee -v decrypt /mnt/c/Users/name/.config/joplin-desktop/resources/c6f30f6834ea42a59196b40074b1f271.crypted
Invalid encryption identifier. Data is not actually encrypted? ID was: /mnt/

```

Not sure what the `/mnt/` there means. Since it's at the beginning, I've tried adding quotes around the path, in case the string just didn't get passed as I'd expect, but it didn't help.

```sql
select * from notes where body like '%c6f30f6834ea42a59196b40074b1f271%';

```

returns the note the resource is referenced from.

However, this:

```sql
select * from resources where id = 'c6f30f6834ea42a59196b40074b1f271';

```

returns 0 rows.

Is there anything else I could try, @laurent ?

Thanks!

---

<div class="post-metadata">

**Author:** ![zblesk](https://yyz2.discourse-cdn.com/flex028/user_avatar/discourse.joplinapp.org/zblesk/32/11_2.png) [@zblesk](https://discourse.joplinapp.org/u/zblesk)\
**Post date:** [4 March 2019 23:02 UTC](https://discourse.joplinapp.org/t/decrypt-single-md-file/640/15 "2019-03-04T23:02:45Z")

</div>

Ok, update:

I got one of them to decrypt, but it probably isn't a great way 😅

I've manually inserted a row into the `resources` table. I've filled in all of the columns based on the rows above them, except I set the value of the last two columns to `1` instead of `0`, because they had the word 'encryption' in them, more or less. 😃 #proTechniques

When I next launched Joplin, the image actually decrypted and displayed correctly. The DB now still has `1` in the `encryption_applied` column, and `0` in `encryption_blob_encrypted`.

However, when I run

```auto
select * from resource_local_states where resource_id = 'c6f30f6834ea42a59196b40074b1f271';

```

there are still 0 rows there.  
I'm not _sure_ there should be one; after all, I have 632 resources, and only 564 resource\_local\_states.  
And I have a baaaad feeling about all these edits.

So what should I do? Do more edits?  
Decrypt them all like this, copy them over somewhere else, restore the DB to the original state and copy the resources there as new files? (Tried this and synced, the other one synced and displayed correctly.)  
Am I at a risk of ruining my sync target somehow? 😃

(I did make a JEX export and a `joplin export` dump and a copy of the sqlite DB before editing anything, so I hope I'm at least recoverable...)

---

<div class="post-metadata">

**Author:** ![laurent](https://avatars.discourse-cdn.com/v4/letter/l/ce7236/32.png) [@laurent](https://discourse.joplinapp.org/u/laurent)\
**Post date:** [4 March 2019 23:20 UTC](https://discourse.joplinapp.org/t/decrypt-single-md-file/640/16 "2019-03-04T23:20:02Z")

</div>

Hmm, I’ve removed the command to decrypt a single file recently because it had some issues, so there’s not any clean way to do it, only hacking like you did.

I think there should be a command like fix\_resources, which would go through the resource files and create a db row for those that miss one. They will then be picked up by the decryption worker and decrypted.

It should be quite easy to add this so I’ll have a look.

But also I wonder how it happened in the first place.

---

<div class="post-metadata">

**Author:** ![zblesk](https://yyz2.discourse-cdn.com/flex028/user_avatar/discourse.joplinapp.org/zblesk/32/11_2.png) [@zblesk](https://discourse.joplinapp.org/u/zblesk)\
**Post date:** [5 March 2019 09:00 UTC](https://discourse.joplinapp.org/t/decrypt-single-md-file/640/17 "2019-03-05T09:00:27Z")

</div>

Thanks. That sounds like a good idea.  
I went ahead and grabbed all of the .crypted files, then removed those whose IDs are in the DB... and got 133 missing resource IDs. That is a bit more than I'd expected.

If I add them en masse, decrypt and sync, do you think I'd fix them all at once without breaking anything?  
If there are any that are no longer referenced, will Joplin still remove them correctly?

Oh yeah, also regarding this:

> [@zblesk](#):
>
> When I next launched Joplin, the image actually decrypted and displayed correctly. The DB now still has `1` in the `encryption_applied` column, and `0` in `encryption_blob_encrypted` .

when I tried the `joplin export` again, it told me some of the resources are not decrypted yet and I should wait until later. When I changed the `encryption_applied` value to 0 manually and tried again, not only did it work, but it also actually _synced_ to my other device correctly this time. (I removed the original resource link from the note and just kept the copy. Wouldn't want to do this manually for \>130 resources, though.)

Should I do this for all of them?

Thanks!

---

<div class="post-metadata">

**Author:** ![laurent](https://avatars.discourse-cdn.com/v4/letter/l/ce7236/32.png) [@laurent](https://discourse.joplinapp.org/u/laurent)\
**Post date:** [11 March 2019 19:39 UTC](https://discourse.joplinapp.org/t/decrypt-single-md-file/640/18 "2019-03-11T19:39:59Z")

</div>

In the latest CLI version I’ve added a command `joplin e2ee decrypt-file /path/to/crypted`, which might help with what you’re trying to do. Note that it’s mainly to recover resources that have lost their metadata (the .md file), and it will simply decrypt the file without adding it to the Joplin database.

---

<div class="post-metadata">

**Author:** ![zblesk](https://yyz2.discourse-cdn.com/flex028/user_avatar/discourse.joplinapp.org/zblesk/32/11_2.png) [@zblesk](https://discourse.joplinapp.org/u/zblesk)\
**Post date:** [11 March 2019 21:52 UTC](https://discourse.joplinapp.org/t/decrypt-single-md-file/640/19 "2019-03-11T21:52:27Z")

</div>

Thanks! I’ve solved the issue the way I’d described above, but this will certainly be handy if it happens again.

One last question: there seem to be a lot of resources (~100) which weren’t referenced from any note, when I did the search in SQLite. My plan is to just ignore them, they don’t hurt anything. But does Joplin do any kind of clean-up on them?

---

<div class="post-metadata">

**Author:** ![laurent](https://avatars.discourse-cdn.com/v4/letter/l/ce7236/32.png) [@laurent](https://discourse.joplinapp.org/u/laurent)\
**Post date:** [11 March 2019 23:09 UTC](https://discourse.joplinapp.org/t/decrypt-single-md-file/640/20 "2019-03-11T23:09:00Z")

</div>

There’s indeed an issue as when the resource gets deleted the crypted file currently stays there while it should be deleted too, so that would indeed need to be fixed at some point.

[Next page](https://discourse.joplinapp.org/t/decrypt-single-md-file/640.md?page=2)
