What I am searching for is a decrypt function to the crypt(3)
function. Reading the manual they only refer me to see login(1), passwd(1), encrypt(3), getpass(3), passwd(5)
, but as far as I am aware, non of them can be used to decrypt the string.
I wrote together a small program to show my point, the function I am looking for is the somefunctogetbackplaintext(...)
#define _XOPEN_SOURCE
#include <unistd.h>
#include <string.h>
#include <stdio.h>
int
main(int argc, char *argv[])
{
char *cryptated = crypt(argv[1], "aa"); // Password and salt
if(strcmp("somepassword", somefunctogetbackplaintext(argv[1], cryptated, "aa"))) //Plain text, cryptated string, salt
{
printf("Success!\n");
}
else
{
printf("Not a success!\n");
}
return 0;
}
Here is a summary excerpt from this article distinguishing between the concepts of encryption and Hashing:
Passwords remain the primary means for online authentication and must be protected when stored on a server. Encryption is an option, but it has an inherent weakness in this application because the server authenticating the password must have the key to decrypt it. An attacker who steals a file of encrypted passwords might also steal the key.
Hashing is a better option, especially with the judicious use of salt, according to mathematician Andrew Regenscheid and computer scientist John Kelsey of the National Institute of Standards and Technology’s Computer Security Division.
Encryption is a two-way function; what is encrypted can be decrypted with the proper key. Hashing, however, is a one-way function that scrambles plain text to produce a unique message digest. With a properly designed algorithm, there is no way to reverse the hashing process to reveal the original password. An attacker who steals a file of hashed passwords must then guess the password.
(emphasis mine)
Also (from comments) this link plainly states: crypt is the library function which is used to compute a password hash...