5 releases

0.2.1 Apr 3, 2023
0.2.0 Sep 12, 2022
0.1.4 Mar 23, 2021
0.1.3 Oct 15, 2019
0.1.0 May 4, 2018

#106 in Cryptography

Download history 1776/week @ 2023-06-01 2649/week @ 2023-06-08 1971/week @ 2023-06-15 2623/week @ 2023-06-22 1888/week @ 2023-06-29 2224/week @ 2023-07-06 2069/week @ 2023-07-13 1940/week @ 2023-07-20 2084/week @ 2023-07-27 1920/week @ 2023-08-03 2434/week @ 2023-08-10 2402/week @ 2023-08-17 1419/week @ 2023-08-24 1783/week @ 2023-08-31 1671/week @ 2023-09-07 964/week @ 2023-09-14

6,176 downloads per month
Used in 4 crates

MPL-2.0 license

453 lines


dependency status

An implementation of fernet in Rust.

What is Fernet?

Fernet is a small library to help you encrypt parcels of data with optional expiry times. It's great for tokens or exchanging small strings or blobs of data. Fernet is designed to be easy to use, combining cryptographic primitives in a way that is hard to get wrong, prevents tampering and gives you confidence that the token is legitimate. You should consider this if you need:

  • Time limited authentication tokens in URLs or authorisation headers
  • To send small blobs of encrypted data between two points with a static key
  • Simple encryption of secrets to store to disk that can be read later
  • Many more ...

Great! How do I start?

Add fernet to your Cargo.toml:

fernet = "0.1"

And then have a look at our [API documentation] online, or run "cargo doc --open" in your project.

Testing Token Expiry

By default fernet wraps operations in an attempt to be safe - you should never be able to "hold it incorrectly". But we understand that sometimes you need to be able to do some more complicated operations.

The major example of this is having your application test how it handles tokens that have expired past their ttl.

To support this, we allow you to pass in timestamps to the encrypt_at_time and decrypt_at_time functions, but these are behind a feature gate. To activate these api's you need to add the following to Cargo.toml

fernet = { version = "0.1", features = ["fernet_danger_timestamps"] }


~68K SLoC