4
$\begingroup$

When I integrate lib sodium, into a c# project, and try to consume, encryption and decryption in a particular way, it works, but the confusion is about, which method to use while encryption or decryption, as it provides various ways to encrypt/decrypt. For example :

1. Lib Sodium : Supports these Encryption Methodologies

2. Lib Sodium : Supports these Encryption Methodologies

3. Lib Sodium : Supports these Encryption Methodologies

Problem Statement 1: Currently, I have multiple applications, in various technologies like, an android App, iOS App (Swift / Objective C), Node Js App, Web API (C#), Web Site (C#), Web Service (Java), Windows Application (C#, C++), there can be more, but these are the first once to be targeted. These application interact with database and my database is encrypted currently with custom aes encryption format (and can only be accessed with C#), moving forward, I think we are finalizing on LibSodium so that same encryption decryption can be implemented in almost all languages.

While exploring Lib Sodium, its confusing to surely know which encryption or decryption, as seen in attached screenshots is the best/the most secured way to go ahead:

  1. Use a best methodology i.e Stream Encryption, CryptoHash etc. (Any one)
  2. Use combinations of multiple Methods, Like first use Stream Encryption and then to go for CryptoHash etc. ( this might have some performance issue).

Problem Statement 2: Another problem which I am facing is, to find similar methods in other programming languages, i.e. If I use Stream Encryption in C#, its known as xor in Node Js, and some other name in c++, then how should I find its equivalent every time in other languages ?

P.S. I did go through the documentation of lib sodium so please don't comment the link of lib sodium

$\endgroup$
3
$\begingroup$

For symmetric encryption (encrypt data with a key, decrypt with the same key) use crypto_secretbox functions or possibly the crypto_secretstream functions. This seems to be what you want for problem 1.

Crypto_generichash() is not an encryption function. It's a hashing function. It takes in a message and spits out a short value known as a hash. The hash is unique per message, and different messages tend to have wildly different hashes. There is no known way to find out what message created a given hash faster than just trying all messages. Likewise there's no known way to find 2 messages that result in the same hash faster than trying all messages.

Problem statement 2: The function names should be the same in the libsodium bindings for all languages. XOR is a logic operation, not a stream encryption function.

It is worth thoroughly reading the documentation, and probably some tutorials about encryption in general. Some of what you're confused about (hashes vs encryption) is very basic, a bit like someone not knowing the difference between equality comparison (==) and assignment (=) and wanting to implement binary search. It makes it a bit difficult for me to formulate a useful answer. There is NOTHING WRONG with not having learned this stuff yet, it's not obvious or generally taught in school. If you want to learn a lot of this I suggest Dan Boneh's coursera course. It's a free graduate level course.

TL;DR: You probably want crypto_secretbox_easy(), though I'm not totally sure based on your short description.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.