Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Best form of Encryption(md5 ect..)
Old 02-21-2009, 04:30 AM Best form of Encryption(md5 ect..)
Red_X_'s Avatar
Extreme Talker

Posts: 158
Location: Houston
Trades: 0
I've been reading around quite a bit comparing different types of php encryption, and other forms of encryption.

So what would you think is the best type of encryption?(md5, SHA1, SHA2, Md5, Md6).
__________________
"Good News Everyone, by reading this your hearing my voice."
Red_X_ is offline
Reply With Quote
View Public Profile Visit Red_X_'s homepage!
 
 
Register now for full access!
Old 02-21-2009, 05:21 AM Re: Best form of Encryption(md5 ect..)
lizciz's Avatar
Super Spam Talker

Posts: 807
Name: Mattias Nordahl
Location: Sweden
Trades: 0
I've been reading up on that too recently :P
First of, it's not encryption but hashing. Th difference beeing that an encryption have a way to decrypt to recieve the original text, while the whole point of a hash is that it can't (within reasonable time).

Now, a (very) short summary of what I've learned. (Oh, and this is for password storing. Things that I say isn't good may be good for other purposes.)

* md5 sucks, it's not random enough and it's waaay too fast.
* There are a couple of hasing algorithms that are good, the best one beeing bcrypt
* You can use this php implementaion of bcrypt.

I started using it in my scrips yeterday and it's working fine
lizciz is offline
Reply With Quote
View Public Profile Visit lizciz's homepage!
 
Old 02-21-2009, 05:24 AM Re: Best form of Encryption(md5 ect..)
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
PHP supports md5 and sha up to 512. MD6 is not supported natively as far as I'm aware and wouldn't be applicable in a lot of cases as it is intended for encryption with very large inputs while utilizing multiple cores efficiently.

All of the encryptions you mentioned with the possible exception of md5 are impractical to crack using brute force, however other more clever means do exist. In short sha512 is more secure than sha1 which is more secure than md5, however I doubt you're going to be experiencing security issues by using sha1 instead of a more robust algorithm.

Just remember to use a salt when encrypting passwords.

Quote:
Originally Posted by lizciz View Post
First of, it's not encryption but hashing. Th difference beeing that an encryption have a way to decrypt to recieve the original text, while the whole point of a hash is that it can't (within reasonable time).
I suppose you could break down the symantics further and claim its not hashing, but cryptographic hashing . A hash function maps a value to an index of a hash table whereas a cryptographic hash function maps a value to a fixed length string.

I agree with your comments regarding md5. I think the inteded use of md5 is for file integrity validation. For password hashing its best to stick to algorithms that are less likely to generate collisions.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE

Last edited by NullPointer; 02-21-2009 at 05:55 AM.. Reason: So many typos, this is what happens when you post at 2:00AM
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 02-21-2009, 05:37 AM Re: Best form of Encryption(md5 ect..)
rogem002's Avatar
PHP Chap

Posts: 843
Name: Mike
Location: United Kingdom
Trades: 0
Here is the best form of hashing:
PHP Code:
<?php
$password 
md5("1234"); // what you want hashing.
$salt md5("dfgdfg"); // some extra crash to tip the boat.

// Firstly, here are some of the native hashes,
$password md5(crc32(sha1($password).$salt));

// this will go through all the hashing's available on the system.
foreach (hash_algos() as $algorythm) {
$password hash($algorythm$salt $password)
}

md5($password); // Just to tidy things up.
?>
However, this does assume that the hash_algos() is not updated. It could be worthwhile making a backup of the list if you need to hash something in the future.
__________________
My Blog/Site:
Please login or register to view this content. Registration is FREE

Last edited by rogem002; 02-21-2009 at 07:24 AM..
rogem002 is offline
Reply With Quote
View Public Profile Visit rogem002's homepage!
 
Old 02-21-2009, 05:50 AM Re: Best form of Encryption(md5 ect..)
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
Quote:
Originally Posted by rogem002 View Post
Here is the best form of hashing:
Lets just hope that another hashing algorithm does not become available at some point or else your strings won't match up.

Honestly I think that method, if used on a large scale, would eat up too much resources for too little an advantage. I'd bet that the resulting hash of that method would be less secure than one from a simpler method such as:

PHP Code:
$password $_POST['password'];
$salt 'c%f';
//I usually generate random salts for each user
//and store them in the database

$hash sha1($salt sha1($password)); 
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE

Last edited by NullPointer; 02-21-2009 at 05:53 AM..
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 02-21-2009, 07:26 AM Re: Best form of Encryption(md5 ect..)
rogem002's Avatar
PHP Chap

Posts: 843
Name: Mike
Location: United Kingdom
Trades: 0
Quote:
Originally Posted by NullPointer View Post
Lets just hope that another hashing algorithm does not become available at some point or else your strings won't match up.
Point taken and post updated.

I think overall, use various hashing methods. For example not just sha1, but like
sha1, md5 and various other one combined.
__________________
My Blog/Site:
Please login or register to view this content. Registration is FREE
rogem002 is offline
Reply With Quote
View Public Profile Visit rogem002's homepage!
 
Old 02-21-2009, 09:12 AM Re: Best form of Encryption(md5 ect..)
wayfarer07's Avatar
Poo on You

Latest Blog Post:
Introducing WowWindow
Posts: 3,987
Name: Abel Mohler
Location: Asheville, North Carolina USA
Trades: 0
I use an md5 hmac when I want to do secure hashing. It is available in the mhash library, but is easy to reproduce if you don't have mhash available:

PHP Code:
    function hmac($data$key) {
        
$b 64// byte length for md5
        
if (strlen($key) > $b) {
        
$key pack("H*",md5($key));
        }
        
$key  str_pad($key$bchr(0x00));
        
$ipad str_pad(''$bchr(0x36));
        
$opad str_pad(''$bchr(0x5c));
        
$k_ipad $key $ipad ;
        
$k_opad $key $opad;
        
        return 
md5($k_opad pack("H*",md5($k_ipad $data)));
    } 
Since an HMAC is a keyed hash, I use this form of hashing for encryption functions. It is supposed to be very strong.
__________________
I build web things. I work for the startup
Please login or register to view this content. Registration is FREE
.

Last edited by wayfarer07; 02-21-2009 at 09:14 AM..
wayfarer07 is online now
Reply With Quote
View Public Profile Visit wayfarer07's homepage!
 
Old 02-21-2009, 12:16 PM Re: Best form of Encryption(md5 ect..)
Red_X_'s Avatar
Extreme Talker

Posts: 158
Location: Houston
Trades: 0
Quote:
Originally Posted by rogem002 View Post
Here is the best form of hashing:
PHP Code:
<?php
$password 
md5("1234"); // what you want hashing.
$salt md5("dfgdfg"); // some extra crash to tip the boat.

// Firstly, here are some of the native hashes,
$password md5(crc32(sha1($password).$salt));

// this will go through all the hashing's available on the system.
foreach (hash_algos() as $algorythm) {
$password hash($algorythm$salt $password)
}

md5($password); // Just to tidy things up.
?>
However, this does assume that the hash_algos() is not updated. It could be worthwhile making a backup of the list if you need to hash something in the future.
There a term for that...and I can't get it...its on the tip of my tounge, a reason why you shouldn't use multiple hash methods (minus the add of salt).
__________________
"Good News Everyone, by reading this your hearing my voice."
Red_X_ is offline
Reply With Quote
View Public Profile Visit Red_X_'s homepage!
 
Old 02-22-2009, 03:08 PM Re: Best form of Encryption(md5 ect..)
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
Quote:
Originally Posted by rogem002 View Post
I think overall, use various hashing methods. For example not just sha1, but like
sha1, md5 and various other one combined.
I have to disagree. So long as you use a proper salt, the resulting hash is just as secure as one that uses multiple hashes. The only thing that matters is the last hash function you use.

So
PHP Code:
md5($salt md5$password )); 
Is equally secure as your method. This is because generating a collision for one hash is just as likely as the other.

For this same reason
PHP Code:
sha1($salt sha1$password )); 
is more secure than your method. This is because hashes generated by sha1 are harder to generate collisions for.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Reply     « Reply to Best form of Encryption(md5 ect..)
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.29895 seconds with 12 queries