String#crypt first 8 characters

  • Thread starter Patrick Plattes
  • Start date
P

Patrick Plattes

Hello,

i had a problem with str.crypt - i got every time the same result. The
problem is, that this method only use the first 8 characters of the string:

irb(main):022:0> "1234567".crypt('aa')
=> "aaOK9MRbwVNmQ"
irb(main):023:0> "12345678".crypt('aa')
=> "aaNN3X.PL2piw"
irb(main):024:0> "123456789".crypt('aa')
=> "aaNN3X.PL2piw"

If it is a feature not a bug, it should not be an undocumented feature
;-) . ruby-doc.org doesn't told me about this behaviour.

Have a nice day,
Patrick
 
C

ChrisH

On Dec 5, 8:08 am, Patrick Plattes
....
i had a problem with str.crypt - i got every time the same result. The
problem is, that this method only use the first 8 characters of the string:
....

A little googling on 'C standard library crypt' led me to :
http://bama.ua.edu/cgi-bin/man-cgi?crypt_unix+5

It turns out the default crypt functionality only uses the first 8
chars, silently ignoring the rest.

Suggest looking into a "real" cryptographic lib. Googling for 'ruby
crypt' gave up:
http://crypt.rubyforge.org/

cheers
 
F

F. Senault

Le 05 décembre à 14:08, Patrick Plattes a écrit :
Hello,

i had a problem with str.crypt - i got every time the same result. The
problem is, that this method only use the first 8 characters of the string:

There are workarounds, but I think that's dependent on the OS.

For instance, the *BSD variants usually allow to use the notation
$n$salt in the salt part of the crypt to choose another algorythm (n=1
-> MD5, n=2 -> Blowfish, n=3 ->NT-Hash, at least on FreeBSD) :
=> "$1$8aezq78a$frgoGqHZ6bRujQt7qQeSP."

It seems to give the same results on some Linuxes and FreeBSD, but I
don't know exactly how portable it is.

Fred
 
P

Patrick Plattes

Thanks for all the ideas and suggestions. I understand how crypt works
and now I use an other method.

Patrick
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top