PBKDF1 is a password based key derivation function which encrypts data with salt based strategy. It is the part of RSA Laboratories’ Public-Key Cryptography Standards (PKCS) series. On the other hand, PBKDF2 is an improved version of its predecessor PBKDF1 with enhanced functional support and technical upgrading. Many significant changes from PBKDF1 can be identified in PBKDF2 as the new version makes key derivation more sophisticated and accurate. The ability of PBKDF2 to produce keys more than 160 bits long is the most ideal feature that was lacking in the previous version making it a more technologically suave system.
This encryption strategy is used in modern web applications. Now, PBKDF1 has been replaced with its successor PBKDF2 and do not come along with modern SDKs. So, for the sake of backward compatibility in many applications, we implemented the logic of encryption in the following two different languages to compare their output on different platforms:
PHP:
function pbkdf1_password($password, $salt, $iter){
$pwlen = strlen($password);
$dlen = $pwlen + 8;
$buf = $password . substr($salt,0,8);
$result = "";
while($iter-- >= 0){
$buf = sha1($buf,true);
}
return $buf;
}
Ruby:
require 'openssl'
def pbkdf1(password, salt, iter)
pwlen = password.size
dlen = pwlen + 8;
buf = "#{password}#{salt.slice(0,8)}"
puts buf.inspect
0.upto iter do
buf = Digest::SHA1.digest(buf)
puts buf
end
buf.each_byte.map{|i| i.ord}
end
0 Comments