Click here to Skip to main content
11,933,253 members (62,114 online)
Click here to Skip to main content
Add your own
alternative version


20 bookmarked

A C# implementation of Unix crypt()

, 30 Dec 2004
Rate this:
Please Sign up or sign in to vote.
A C# version of the Unix crypt() algorithm.


At my office, we are currently working on a major overhaul of some of our core systems. The 'strategic' decision was made to lose most of our Unix machines and move to a more Microsoft oriented platform. One of the changes caused by this decision was the use of the Microsoft Provisioning System, so all the scripts we made over the years to help us run the business have to be converted for use by the MPF (Microsoft Provisioning Framework). We are changing the systems in a few steps, so at one point, we will have an MPS-based front-end, talking to the Unix back-end. At that point, the MPS will create the new user accounts, but because almost none of the servers and applications using the data from those user accounts have yet been converted, we need to be able to provide them with the information they are expecting. In this case, some of the applications expect a user account to contain a password encrypted with the Unix crypt() system call. Thanks to the beauty of open source, the source code for that system call is widely available, and I was quickly able to find some source I could work with and port to C# (which we are using to create our custom MPF providers with).

Using the code

Using the code is very straightforward. Either put the class in your own application, or put it in a class library. There are two calls:

string Crypt(string textToEncrypt);


string Crypt(string encryptionSalt, string textToEncrypt);

Both are static members. If you use the first method, it will randomly generate the salt characters for you and then call the second method. Salt, in this case, are two letters that are used to provide some extra randomness for the encryption, and allow you to repeat any previous encryption (if you also have the text that was encrypted).

Another thing users should know is that the text to encrypt should not be more then 8 characters long. If your text is longer than 8 characters, only the first 8 are used and the rest is ignored.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Jeroen-bart Engelen
Web Developer
Netherlands Netherlands
Working as a Software Engineer at Internet Solutions, the KPN (Royal Dutch Telecom) department that delivers the ICT for, amongst others, the biggest ISP in the Netherlands.

You may also be interested in...

Comments and Discussions

GeneralMy vote of 5 Pin
wsc09184-Jul-12 21:32
memberwsc09184-Jul-12 21:32 
QuestionThank you Pin
kamalindu22-Mar-12 9:17
memberkamalindu22-Mar-12 9:17 
QuestionUsage of the Unix Crypt. Pin
Sravan rao7-Dec-11 1:43
memberSravan rao7-Dec-11 1:43 
GeneralMy vote of 5 Pin
Scott Wayne Shepherd7-Oct-11 14:43
memberScott Wayne Shepherd7-Oct-11 14:43 
GeneralI'm confused about the 8 character limit Pin
bwechner1-Jun-11 18:18
memberbwechner1-Jun-11 18:18 
GeneralMy vote of 5 Pin
mrstratman@hotmail.com29-Mar-11 8:56
membermrstratman@hotmail.com29-Mar-11 8:56 
GeneralIndexOutOfRangeException Pin
Jordanwb4-Feb-11 14:31
memberJordanwb4-Feb-11 14:31 
GeneralRe: IndexOutOfRangeException Pin
jonathandandries20-Oct-11 7:56
memberjonathandandries20-Oct-11 7:56 
Generalmd5 Pin
mayrand27-Apr-10 5:58
membermayrand27-Apr-10 5:58 
QuestionProblem With $ caracter Pin
st20156-Mar-09 14:21
memberst20156-Mar-09 14:21 
AnswerRe: Problem With $ caracter Pin
Miguel Correia Lima22-Feb-11 1:07
memberMiguel Correia Lima22-Feb-11 1:07 
GeneralRe: Problem With $ caracter Pin
jonathandandries20-Oct-11 7:57
memberjonathandandries20-Oct-11 7:57 
GeneralTHANK YOU! Pin
mpaine_ciber16-Oct-08 11:00
membermpaine_ciber16-Oct-08 11:00 
Generalthankyou Pin
MacManzo24-Sep-08 10:01
memberMacManzo24-Sep-08 10:01 
QuestionPHP crypt() function implementation in C# Pin
darkocobe3-Dec-07 22:44
memberdarkocobe3-Dec-07 22:44 
AnswerRe: PHP crypt() function implementation in C# Pin
jonathandandries20-Oct-11 7:54
memberjonathandandries20-Oct-11 7:54 
QuestionOpen Source Usage Pin
dscsekhar7-Aug-07 3:30
memberdscsekhar7-Aug-07 3:30 
AnswerRe: Open Source Usage Pin
Jeroen-bart Engelen7-Aug-07 4:15
memberJeroen-bart Engelen7-Aug-07 4:15 
GeneralRe: Open Source Usage Pin
Jeroen-bart Engelen7-Aug-07 4:20
memberJeroen-bart Engelen7-Aug-07 4:20 
GeneralThank you so much Pin
RTeja17-Nov-06 2:48
memberRTeja17-Nov-06 2:48 
Questionthanks for the there one that supports MD5 too? Pin
Srivalli1-Jun-06 15:48
memberSrivalli1-Jun-06 15:48 
AnswerRe: thanks for the there one that supports MD5 too? Pin
Jeroen-bart Engelen1-Jun-06 16:21
memberJeroen-bart Engelen1-Jun-06 16:21 
GeneralThank You Pin
pandhoffman19-Apr-06 9:55
memberpandhoffman19-Apr-06 9:55 
GeneralPerfect! Pin
Adam Wimsatt5-Jan-05 4:50
memberAdam Wimsatt5-Jan-05 4:50 
GeneralRe: Perfect! Pin
Jeroen-bart Engelen5-Jan-05 7:46
memberJeroen-bart Engelen5-Jan-05 7:46 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.151126.1 | Last Updated 30 Dec 2004
Article Copyright 2004 by Jeroen-bart Engelen
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid