Click here to Skip to main content
Licence 
First Posted 30 Dec 2004
Views 51,727
Bookmarked 20 times

A C# implementation of Unix crypt()

By | 30 Dec 2004 | Article
A C# version of the Unix crypt() algorithm.

Introduction

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);

and:

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.

License

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

Member

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.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
QuestionThank you Pinmemberkamalindu8:17 22 Mar '12  
QuestionUsage of the Unix Crypt. PinmemberSravan rao0:43 7 Dec '11  
GeneralMy vote of 5 PinmemberScott Wayne Shepherd13:43 7 Oct '11  
GeneralI'm confused about the 8 character limit Pinmemberbwechner17:18 1 Jun '11  
GeneralMy vote of 5 Pinmembermrstratman@hotmail.com7:56 29 Mar '11  
GeneralIndexOutOfRangeException PinmemberJordanwb13:31 4 Feb '11  
GeneralRe: IndexOutOfRangeException Pinmemberjonathandandries6:56 20 Oct '11  
Generalmd5 Pinmembermayrand4:58 27 Apr '10  
QuestionProblem With $ caracter Pinmemberst201513:21 6 Mar '09  
AnswerRe: Problem With $ caracter PinmemberMiguel Correia Lima0:07 22 Feb '11  
GeneralRe: Problem With $ caracter Pinmemberjonathandandries6:57 20 Oct '11  
GeneralTHANK YOU! Pinmembermpaine_ciber10:00 16 Oct '08  
Generalthankyou PinmemberMacManzo9:01 24 Sep '08  
QuestionPHP crypt() function implementation in C# Pinmemberdarkocobe21:44 3 Dec '07  
AnswerRe: PHP crypt() function implementation in C# Pinmemberjonathandandries6:54 20 Oct '11  
QuestionOpen Source Usage Pinmemberdscsekhar2:30 7 Aug '07  
Can I use this source code in our project straight away? Or do I need to get some licensing for this?
AnswerRe: Open Source Usage PinmemberJeroen-bart Engelen3:15 7 Aug '07  
GeneralRe: Open Source Usage PinmemberJeroen-bart Engelen3:20 7 Aug '07  
GeneralThank you so much PinmemberRTeja1:48 17 Nov '06  
Questionthanks for the code...is there one that supports MD5 too? PinmemberSrivalli14:48 1 Jun '06  
AnswerRe: thanks for the code...is there one that supports MD5 too? PinmemberJeroen-bart Engelen15:21 1 Jun '06  
GeneralThank You Pinmemberpandhoffman8:55 19 Apr '06  
GeneralPerfect! PinmemberAdam Wimsatt3:50 5 Jan '05  
GeneralRe: Perfect! PinmemberJeroen-bart Engelen6:46 5 Jan '05  
QuestionWhat is "MPS"? PinsitebuilderUwe Keim20:03 30 Dec '04  

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

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

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