# An intuitive crypto lib recommendation

**URL:** <https://discuss.ocaml.org/t/an-intuitive-crypto-lib-recommendation/14330>\
**Category:** Ecosystem\
**Tags:** encryption\
**Created:** [March 19, 2024, 3:19pm UTC](https://discuss.ocaml.org/t/an-intuitive-crypto-lib-recommendation/14330 "2024-03-19T15:19:29Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![msbic](https://avatars.discourse-cdn.com/v4/letter/m/ce7236/32.png) [@msbic](https://discuss.ocaml.org/u/msbic)\
**Post date:** [March 19, 2024, 3:19pm UTC](https://discuss.ocaml.org/t/an-intuitive-crypto-lib-recommendation/14330/1 "2024-03-19T15:19:29Z")

</div>

Hi all.

I’d like to write a simple command line password manager for myself as a fun project.  
What’s a good crypto lib to use? Hopefully with examples.

---

<div class="post-metadata">

**Author:** ![yawaramin](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/yawaramin/32/3384_2.png) [@yawaramin](https://discuss.ocaml.org/u/yawaramin)\
**Post date:** [March 19, 2024, 8:31pm UTC](https://discuss.ocaml.org/t/an-intuitive-crypto-lib-recommendation/14330/2 "2024-03-19T20:31:52Z")

</div>

I actually haven’t seen any encryption libraries that are as easy to use as Dream’s functions: [Dream — Tidy, feature-complete web framework](https://aantron.github.io/dream/#cryptography)

Of course there are other more powerful libraries, but Dream’s `encrypt` and `decrypt` seem good enough for a lot of use cases. You may be able to copy over the relevant parts of the source code if you don’t want the entire Dream dependency cone, of course.

---

<div class="post-metadata">

**Author:** ![dbuenzli](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/dbuenzli/32/18_2.png) [@dbuenzli](https://discuss.ocaml.org/u/dbuenzli)\
**Post date:** [March 19, 2024, 8:55pm UTC](https://discuss.ocaml.org/t/an-intuitive-crypto-lib-recommendation/14330/3 "2024-03-19T20:55:35Z")

</div>

If you are familiar with tweetnacl. There are bindings [here](https://erratique.ch/software/ttweetnacl/doc/Ttweetnacl/index.html).

---

<div class="post-metadata">

**Author:** ![msbic](https://avatars.discourse-cdn.com/v4/letter/m/ce7236/32.png) [@msbic](https://discuss.ocaml.org/u/msbic)\
**Post date:** [March 20, 2024, 2:54pm UTC](https://discuss.ocaml.org/t/an-intuitive-crypto-lib-recommendation/14330/4 "2024-03-20T14:54:24Z")

</div>

Thanks, I will have a look.

---

<div class="post-metadata">

**Author:** ![msbic](https://avatars.discourse-cdn.com/v4/letter/m/ce7236/32.png) [@msbic](https://discuss.ocaml.org/u/msbic)\
**Post date:** [March 20, 2024, 2:55pm UTC](https://discuss.ocaml.org/t/an-intuitive-crypto-lib-recommendation/14330/5 "2024-03-20T14:55:02Z")

</div>

Thanks a lot, I will have a look.

---

<div class="post-metadata">

**Author:** ![sanette](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/sanette/32/1645_2.png) [@sanette](https://discuss.ocaml.org/u/sanette)\
**Post date:** [March 20, 2024, 5:15pm UTC](https://discuss.ocaml.org/t/an-intuitive-crypto-lib-recommendation/14330/6 "2024-03-20T17:15:30Z")

</div>

didn’t try it myself, but Argon2 is specifically tailored for passwords

> **[GitHub - Khady/ocaml-argon2: Ocaml bindings to Argon2](https://github.com/Khady/ocaml-argon2)**
>
> Ocaml bindings to Argon2. Contribute to Khady/ocaml-argon2 development by creating an account on GitHub.

(passwords should be hashed and not encrypted)

---

<div class="post-metadata">

**Author:** ![dbuenzli](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/dbuenzli/32/18_2.png) [@dbuenzli](https://discuss.ocaml.org/u/dbuenzli)\
**Post date:** [March 20, 2024, 5:30pm UTC](https://discuss.ocaml.org/t/an-intuitive-crypto-lib-recommendation/14330/7 "2024-03-20T17:30:07Z")

</div>

> [@sanette](#):
>
> (passwords should be hashed and not encrypted)

@msbic wants to write a _password manager_, not store the user passwords of a service (in which case you are right).

---

<div class="post-metadata">

**Author:** ![pukkamustard](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/pukkamustard/32/2330_2.png) [@pukkamustard](https://discuss.ocaml.org/u/pukkamustard)\
**Post date:** [March 21, 2024, 8:25am UTC](https://discuss.ocaml.org/t/an-intuitive-crypto-lib-recommendation/14330/8 "2024-03-21T08:25:35Z")

</div>

There are also some bindings to [Monocypher](https://monocypher.org/): [eris/ocaml-monocypher - Codeberg.org](https://codeberg.org/eris/ocaml-monocypher)

---

<div class="post-metadata">

**Author:** ![UnixJunkie](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/unixjunkie/32/638_2.png) [@UnixJunkie](https://discuss.ocaml.org/u/UnixJunkie)\
**Post date:** [March 22, 2024, 1:22am UTC](https://discuss.ocaml.org/t/an-intuitive-crypto-lib-recommendation/14330/9 "2024-03-22T01:22:54Z")

</div>

Not sure it is intuitive, especially because it has an object interface instead  
of a functional one, but it does the job:

> **[GitHub - xavierleroy/cryptokit: A library of cryptographic primitives...](https://github.com/xavierleroy/cryptokit)**
>
> A library of cryptographic primitives (ciphers, hashes, etc) for OCaml - xavierleroy/cryptokit

---

<div class="post-metadata">

**Author:** ![yawaramin](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/yawaramin/32/3384_2.png) [@yawaramin](https://discuss.ocaml.org/u/yawaramin)\
**Post date:** [March 22, 2024, 1:37am UTC](https://discuss.ocaml.org/t/an-intuitive-crypto-lib-recommendation/14330/10 "2024-03-22T01:37:34Z")

</div>

Good suggestion. the [RSA](https://ocaml.org/p/cryptokit/latest/doc/Cryptokit/RSA/index.html) module seems like a nice functional API for asymmetric encryption.

---

<div class="post-metadata">

**Author:** ![emillon](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/emillon/32/1206_2.png) [@emillon](https://discuss.ocaml.org/u/emillon)\
**Post date:** [March 22, 2024, 8:54am UTC](https://discuss.ocaml.org/t/an-intuitive-crypto-lib-recommendation/14330/11 "2024-03-22T08:54:46Z")

</div>

This RSA module exposes only very low level primitives. It’s not something you should directly use to store encrypted passwords.

---

<div class="post-metadata">

**Author:** ![msbic](https://avatars.discourse-cdn.com/v4/letter/m/ce7236/32.png) [@msbic](https://discuss.ocaml.org/u/msbic)\
**Post date:** [March 22, 2024, 1:48pm UTC](https://discuss.ocaml.org/t/an-intuitive-crypto-lib-recommendation/14330/12 "2024-03-22T13:48:07Z")

</div>

Great suggestions. Thanks everyone!  
I will evaluate them all

---

<div class="post-metadata">

**Author:** ![yawaramin](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/yawaramin/32/3384_2.png) [@yawaramin](https://discuss.ocaml.org/u/yawaramin)\
**Post date:** [March 22, 2024, 2:05pm UTC](https://discuss.ocaml.org/t/an-intuitive-crypto-lib-recommendation/14330/13 "2024-03-22T14:05:37Z")

</div>

Why not? It looks like I can create a keypair and use it to encrypt a string into ciphertext. Can’t I then just store that ciphertext string?

---

<div class="post-metadata">

**Author:** ![emillon](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/emillon/32/1206_2.png) [@emillon](https://discuss.ocaml.org/u/emillon)\
**Post date:** [March 22, 2024, 2:18pm UTC](https://discuss.ocaml.org/t/an-intuitive-crypto-lib-recommendation/14330/14 "2024-03-22T14:18:52Z")

</div>

Look at the docs (or implementation) for `encrypt`: it can only encrypt data shorter than the key, which means you’ll need a padding algorithm and couple it with a symmetric cipher to do hybrid encryption. In every of these steps you can shoot yourself in the foot.  
Not to say that it’s not valuable or that people shouldn’t try to do these things, but that’s a different project. It’s not “an intuitive crypto lib”.  
If you’re interested, [Cryptopals set 6](https://cryptopals.com/sets/6) explores problems with RSA.
