Questions tagged [crypt]

crypt() is Unix C library function used for hashing passwords. It is also found in PHP, Perl, Python and various other languages.

crypt(3) is a Unix C library function used for hashing passwords. The crypt() function takes in a password and an optional salt string (chosen randomly if not supplied), and calculates a cryptographic message digest based on them. The digest includes the salt used to generate it, so that, when the user re-enters their password, the digest can be recalculated and compared with the previously stored value.

Despite its name, the crypt(3) function cannot actually be used to encrypt data; the transformation it implements is deliberately non-reversible, so that its output cannot be decrypted to recover the original password.

The "traditional" hashing algorithm used by the original Unix crypt(3) was based on a modified version of the DES block cipher, and only supported passwords of up to 8 characters, with 7 bits per character, and a two-character salt with 6 bits per character. This algorithm is nowadays considered insecure due to its limited keyspace and high speed, which allow an attacker using modern computers to test all possible passwords by brute force in a relatively short time. Nonetheless, most crypt(3) implementations still include it for the sake of backwards compatibility.

Most modern crypt(3) implementations include various alternative hashing algorithms, which typically support arbitrarily long passphrases, longer salts and adjustable iteration counts to deliberately slow down the digest calculation for key stretching. One well known example of such an algorithm is , which is based on the Blowfish cipher.

Functions similar in name and purpose to (and possibly implemented by) the Unix crypt(3) function are also found in several high-level languages, including PHP, Perl and Python.

The crypt(3) function should not be confused with the Unix command line utility crypt(1), which is an obsolete and insecure file encryption utility. For a modern replacement, see .

553 questions
10
votes
2 answers

Rfc2898DeriveBytes in java

I am trying to implement the following code in java: var keyGenerator = new Rfc2898DeriveBytes(password, salt, 1000); byte[] key = keyGenerator.GetBytes(32); byte[] iv = keyGenerator.GetBytes(16); using (AesManaged aes = new AesManaged()) { …
rgolovakha
  • 518
  • 2
  • 5
  • 17
9
votes
5 answers

Good cryptographic hash functions

Possible Duplicate: Secure hash and salt for PHP passwords I am making a website, and I need a secure algorithm to store passwords. I was first thinking of bcrypt, but then I found out my host did not support it and I am not able to change…
SnackerSWE
  • 649
  • 1
  • 10
  • 19
9
votes
5 answers

PHP crypt() returning wrong answer

I think i'm losing my marbles here... I've got a problem on my web site where randomly it stops accepting logins. I've now been able to trace it to crypt() behaving very strangely. In my database, i've got the crypted version of the users password…
Matt Peddlesden
  • 520
  • 1
  • 5
  • 12
9
votes
2 answers

Why shouldn't I use the 23rd character in a crypt() function's salt?

I'm learning about PHP's crypt() function and have been running some tests with it. According to this post, I should use a salt that's 22 characters long. I can, however, use a string that's 23 characters long with some limitations. When I use a 22…
Andrew
  • 546
  • 4
  • 17
9
votes
3 answers

Exactly how do I use blowfish in PHP?

Possible Duplicate: Best way to use PHP to encrypt and decrypt passwords? I've been doing a lot with PHP recently and want to make my first login/registration system. As such I've been doing a lot of reading online to figure out the best…
sharf
  • 2,123
  • 4
  • 24
  • 47
8
votes
1 answer

How to get same crypt(3) function in Mac OS X as Linux gcc/gnu crypt(3)? Linux gcc crypt(3) has MD5 and SHA512. Apple Gcc crypt(3) *only* uses DES

I am migrating some c code from Linux to Mac OSX (yosemite). The Mac OSX crypt() function (which is in unistd.h, as I have determined), is not the same as on gcc/gnu in Linux. I have test programs on Linux and Mac OSX, and the crypt() c-library…
Rusfuture
  • 157
  • 2
  • 10
8
votes
7 answers

Is there a way to reverse a crypt() in c?

Not sure if this is possible but I want to be able to start with a string, and then figure out what the input must be into the crypt in order to get this string out. Or maybe it's impossible, which would be the whole purpose of the thing…
MetaGuru
  • 42,847
  • 67
  • 188
  • 294
8
votes
4 answers

Is it secure to store a PHP crypt() result in the db?

For example with blowfish it returns something like: $2a$12$DEzG.CRsHpxpTOAHooQ.wuR6Xe9h6PxFPhOcOvf.lqDNw1TVYVnEO That contains info about the type of hashing alg and it contains the salt. A lot of resources say to just store this value in the db…
Ryan
  • 5,883
  • 13
  • 56
  • 93
7
votes
3 answers

crypt(3) $6$ password hash algorithm (based on SHA-512) in Java?

I'm looking for a Java function to generate/verify password hashes that were encoded in the way crypt(3) does when storing them in the Linux "/etc/shadow" file if sha512 is activated in "/etc/pam.d/common-password". The plaintext string "geheim"…
lathspell42
  • 603
  • 3
  • 7
  • 11
7
votes
1 answer

Using ruby to generate SHA512 crypt-style hashes formatted for /etc/shadow?

I want to generate SHA512 hashed passwords for inclusion directly into a /etc/shadow file for use with chef's user resource. Normally I'd go to the stdlib's Digest library for this, but it doesn't generate the hash in the right…
Gabe Martin-Dempesy
  • 7,687
  • 4
  • 33
  • 24
7
votes
1 answer

golang equivalent of PHP crypt()

This line of code in PHP evaluates to true echo '$2a$09$f5561d2634fb28a969f2dO8QeQ70f4bjCnF/.GvPpjj.8jgmtzZP2' == crypt("enter-new-password",'$2a$09$f5561d2634fb28a969f2dO8QeQ70f4bjCnF/.GvPpjj.8jgmtzZP2'); What I need is a crypt function in Golang…
John
  • 32,403
  • 80
  • 251
  • 422
7
votes
6 answers

crypt function and link error "undefined reference to 'crypt'"

I have used the crypt function in c to encrypt the given string. I have written the following code, #include #include int main() { printf("%s\n",crypt("passwd",1000)); } But the above code threw an error ,"undefined…
kiruthika
  • 2,155
  • 7
  • 26
  • 33
7
votes
1 answer

(PHP) How to correctly implement crypt()

Here is the example from the PHP manual page for crypt():
Tony Stark
  • 24,588
  • 41
  • 96
  • 113
7
votes
3 answers

Correctly using crypt() with SHA512 in PHP

All the examples online show the use of crypt like this: $pass = crypt('something','$6$rounds=5000$anexamplestringforsalt$'); But everyone says that you are not supposed to define the rounds or the salt. So how should I use it? Also I am having a…
ShadowZzz
  • 415
  • 2
  • 5
  • 17
6
votes
2 answers

Alternative to crypt()

I am working on a script and need to save passwords. For development purposes, I have been using the crypt() function because it was easy and available. Now that I am mostly done, I want to replace it with something a little better and more…
steveo225
  • 11,394
  • 16
  • 62
  • 114
1
2
3
36 37