Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

python glibc crypt() function

10 views
Skip to first unread message

luca72

unread,
Apr 20, 2010, 9:54:55 AM4/20/10
to
Hello i have to do this :
glibc crypt() function, using salt $1$abcdefgh$

cryptPw = crypt(plainPw, "$1$abcdefgh$")

I can do it in python, with package i need?
Thanks

geremy condra

unread,
Apr 20, 2010, 10:12:24 AM4/20/10
to luca72, pytho...@python.org

Peter Otten

unread,
Apr 20, 2010, 1:38:25 PM4/20/10
to
luca72 wrote:

>>> import ctypes
>>> lib = ctypes.CDLL("libcrypt.so.1")
>>> crypt = lib.crypt
>>> crypt.restype = ctypes.c_char_p
>>> crypt("password", "$1$abcdefgh$")
'$1$abcdefgh$G//4keteveJp0qb8z2DxG/'

Is that what it's supposed to return?

Peter

Peter Otten

unread,
Apr 20, 2010, 3:54:50 PM4/20/10
to
geremy condra wrote:

> Seems like my posts are dropping off of the net all of a sudden.
> In case this didn't go through the first time...
>
> http://docs.python.org/py3k/library/crypt.html#module-crypt
>
> Geremy Condra

This particular post did get get through, it is even marked as read over
here.

Sorry for any confusion my pointless answer may have caused.

Peter

geremy condra

unread,
Apr 20, 2010, 3:03:12 PM4/20/10
to Peter Otten, pytho...@python.org
On Tue, Apr 20, 2010 at 1:38 PM, Peter Otten <__pet...@web.de> wrote:

Дамјан Георгиевски

unread,
Apr 20, 2010, 5:26:03 PM4/20/10
to

seeing this I thought about using ctypes for AES (or similar) crypto
function. A bit of google searching I've come to
http://code.google.com/p/ctypescrypto/

just FYI


--
дамјан ((( http://damjan.softver.org.mk/ )))

... knowledge is exactly like power - something
to be distributed as widely as humanly possible,
for the betterment of all. -- jd

geremy condra

unread,
Apr 20, 2010, 9:16:35 PM4/20/10
to Дамјан Георгиевски, pytho...@python.org
2010/4/20 Дамјан Георгиевски <gda...@gmail.com>:

>>> Hello i have to do this :
>>> glibc crypt() function, using salt $1$abcdefgh$
>>>
>>> cryptPw = crypt(plainPw, "$1$abcdefgh$")
>>>
>>> I can do it in python, with package i need?
>>> Thanks
>>
>>>>> import ctypes
>>>>> lib = ctypes.CDLL("libcrypt.so.1")
>>>>> crypt = lib.crypt
>>>>> crypt.restype = ctypes.c_char_p
>>>>> crypt("password", "$1$abcdefgh$")
>> '$1$abcdefgh$G//4keteveJp0qb8z2DxG/'
>>
>> Is that what it's supposed to return?
>
> seeing this I thought about using ctypes for AES (or similar) crypto
> function. A bit of google searching I've come to
> http://code.google.com/p/ctypescrypto/
>
> just FYI

ctypescrypto does not appear to be maintained, but I've started
a similar project called evpy (http://gitorious.org/evpy) that also
provides envelope encryption. Comments are welcome- we're
probably going to be doing our first release sometime towards
the middle of next month.

Geremy Condra

luca72

unread,
Apr 21, 2010, 2:29:57 AM4/21/10
to
On 20 Apr, 19:38, Peter Otten <__pete...@web.de> wrote:
> luca72 wrote:
> > Hello i have to do this :
> > glibc crypt() function, using salt $1$abcdefgh$
>
> > cryptPw = crypt(plainPw, "$1$abcdefgh$")
Thanks
The result is correct i obtain the same with ctypes and crypt module,
so i think that is better to use the crypt module is correct?

Luca

Peter Otten

unread,
Apr 21, 2010, 3:31:46 AM4/21/10
to
luca72 wrote:

> On 20 Apr, 19:38, Peter Otten <__pete...@web.de> wrote:
>> luca72 wrote:
>> > Hello i have to do this :
>> > glibc crypt() function, using salt $1$abcdefgh$
>>
>> > cryptPw = crypt(plainPw, "$1$abcdefgh$")
> Thanks
> The result is correct i obtain the same with ctypes and crypt module,
> so i think that is better to use the crypt module is correct?

Yes, use the crypt module.

geremy condra

unread,
Apr 21, 2010, 9:49:01 AM4/21/10
to luca72, pytho...@python.org
On Wed, Apr 21, 2010 at 2:29 AM, luca72 <luca...@libero.it> wrote:
> On 20 Apr, 19:38, Peter Otten <__pete...@web.de> wrote:
>> luca72 wrote:
>> > Hello i have to do this :
>> > glibc crypt() function, using salt $1$abcdefgh$
>>
>> > cryptPw = crypt(plainPw, "$1$abcdefgh$")
> Thanks
> The result is correct i obtain the same with ctypes and crypt module,
> so i think that is better to use the crypt module is correct?
>
> Luca

Be aware that the beginning of the salt string determines the
type of hash you're using, and it looks to me like that's the
old-style MD5-based hash. It's far from 'broken', but it has a
few issues. Better would be to move to the SHA512-based
$6$ if your platform supports it.

Geremy Condra

0 new messages