Shadow file encryption method


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Shadow file encryption method
# 1  
Old 10-01-2004
Question Shadow file encryption method

Hi all,

I'd like to use the encryption method used to generate the /etc/shadow passwords.

The goal is to write a script that get a plain-text password as argument and returns an encrycped one.

Can you help me, please?
# 2  
Old 10-02-2004
hai

To encrypt the password you have a function called crypt.. I have used the function in c. The prototype of the function is

char * crypt(const char * pass, const char * key);

the first argument is the password to encrypt
the second one is the key to encrypt the password
the function returns the encrypted password

example program

/* cryp.c */
#include <stdio.h>
#include <unistd.h>
#include <crypt.h>
main()
{
printf("%s\n",crypt("mypassword","B"));
}

compilation:
gcc -lcrypt cryp.c

Output:
BBVV5v7k.VS2.
returns the excrypted password of the string "mypassword" with the encryption key as B

Note: the key to encrypt will always be the first char in the output

Goodluck
Collins
# 3  
Old 10-02-2004
It works !!! Many thanks.

A question, I've tried to run with a 1 character encryption key (e.g."X") and the output string was like "X.xxxxxxxxxxx".

To eliminate the . between key and crypted string I had to use a 2 characters key, e.g.:
"AB" -> "ABxxxxxxxxxxx"

Is this a normal behaviour?

Thanks again.
# 4  
Old 10-04-2004
hai nisant

The length of the key should be two characters. If the user passes only one character for the key field the function puts the same character twice.

so if the key is X ,
the output would be something like
XX<remaining encrypted pass>

if the key is two char length, then the first two char of the encrypted password will be the same as that of the passed argument... Hope i am right

Have a nice time
Collins
# 5  
Old 10-04-2004
Actually, in a call like:
printf("%s\n",crypt("mypassword","B"));

That first argument, the password to be encrypted, is called the "key". The second argument is called the "salt". The salt is required to be two characters from the set [a-zA-Z0-9./]. Calling crypt() with anything other than a properly constructed two character salt is an error. The results of such a call are undefined. One implementation may use "BB" and another "B.". Still another might return an error. So please use two character salts.
# 6  
Old 10-04-2004
I've tried using this code:

char k[2];
char str[255];

scanf("%s",k);
scanf("%s",str);
printf("%s\n",crypt(str,k));

Entering only 1 character to k variable I verify that encrypted string begins with key character repeated twice.
Tested on Solaris and HP-UX SO.

The previous test was executed on Mac OS Linux environment, maybe there are some little differences in gcc and/or libcrypto libraries.

However, it seems I can change the password in unattended mode using a C pgm tha returns the encrypted pwd because I also verified that both the encrypted pwds returned by C pgm and passwd command are the same.

So many thanks, Collins, for your help Smilie .

Bye
nisant
# 7  
Old 10-04-2004
Thank you, Perderabo, for specifying the possible behaviours in coding an only 1 character "salt" in crypt() call.

Bye
nisant
 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Cybersecurity

File encryption tools with MAC address as an encryption key

Hi all, I'm looking for secure file encryption tools that use MAC address as encryption key. FYI, I'm using Red Hat Enterprise Linux OS. For example: when A wants to send file to B A will encrypt the file with B's computer MAC/IP address as an encryption key This file can only be decrypted... (2 Replies)
Discussion started by: sergionicosta
2 Replies

2. UNIX for Dummies Questions & Answers

Shadow file help

As a part of linux hardening In shadow file all Application accounts which are not locked must contain only an asterisk “*” in the Passwd field. But how would i do it by using command? Is there any way other than modifying shadow file to accomplish this task? (3 Replies)
Discussion started by: pinga123
3 Replies

3. Shell Programming and Scripting

Shadow file

Hi, In shadow file smithj:Ep6mckrOLChF.:10063:0:99999:7::: 3rd Field 10063 indicates the number of days (since January 1, 1970) since the password was last changed. I want to get the result with script the date on which the password was last changed in YYYY-MM-DD format. can... (8 Replies)
Discussion started by: pinnacle
8 Replies

4. UNIX for Dummies Questions & Answers

Shadow File

I see conflicting definitions for the shadow file. For Solaris, what are the fields please? Thanks. (3 Replies)
Discussion started by: DavidS
3 Replies

5. UNIX for Advanced & Expert Users

/etc/shadow file....

Does anyone know what "!!" represents in the password field of the /etc/shadow file? :confused: (6 Replies)
Discussion started by: avcert1998
6 Replies

6. Solaris

*LK* in /etc/shadow file

my etc/shadow file showing *LK* for a particular user.. can u tell me under which circumstances a user is locked (5 Replies)
Discussion started by: vikashtulsiyan
5 Replies

7. UNIX for Dummies Questions & Answers

File encryption/Key encryption ????

My dilemma, I need to send, deemed confidential, information via e-mail (SMTP). This information is sitting as a file on AIX. Typically I can send this data as a e-mail attachment via what we term a "mail filter" using telnet. I now would like to somehow encrypt the data and send it to a e-mail... (1 Reply)
Discussion started by: hugow
1 Replies

8. UNIX for Dummies Questions & Answers

shadow file

Sirs, What is a shadow file,How it be usefull.For my project i have to keep the password in shawdow file also i am doing in php how can i do it. Thanks in advance, ArunKumar (3 Replies)
Discussion started by: arunkumar_mca
3 Replies

9. Shell Programming and Scripting

which encryption method?

hello ppl, i've been coding a perl script for xchat and i need to store the nick's passwords. i was wondering which encryption to use. picture this situation: i've got a system flaw and some guy hacks the machine and gets his hands on the passwd file; he has access to the script. what encryption... (2 Replies)
Discussion started by: crashnburn
2 Replies
Login or Register to Ask a Question