Rust encryption

I am a newbi, and not sure if this is the place to ask for help.
I want a encrypt/decrypt function,
fn encrypt(a: &str) -> String fn decrypt(a: &str) -> String


I want to use des, or aes ( not even sure what they mean), but it seems really difficult to create such functions, I asked AI, googled libraries, but they all seems supriingly complicated, and I can not make the compiler happy, simply because some type does not exist in some lib even AI said so.
Any help with a complete example of encryption?
Thanks,

Check out https://cryptopals.com/ for a fairly complete self directed training course on writing encryption.

Do you specifically need to write the encryption yourself, or are you looking for a library that supports encryption?

If the latter, consider using either rustls, aws-lc, or rust-crypto, depending on your needs.

Beware that functions exactly like the ones you specified will most likely do only encoding, which is not encryption, and isn't ensuring security/privacy of the data.

Encryption always requires some form of secret or private key. If you're not providing a key/secret, you're not encrypting.

Encrypted data usually needs additional information about parameters used when encrypting, as well as a digest/hash/mac/checksum that ensures the encrypted data hasn't been manipulated. This is why you end up with more complex APIs and output that is more than just a string.

I assume you mean the RustCrypto GitHub organization, rust-crypto is an unmaintained crate. Important difference :slight_smile:

1 Like

Yes, that's exactly what I meant. Thank you for clarifying.

This post looks like a better fit for users.rust-lang.org, so I’m moving it over there: