Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 1 of 1
Thread: Crypting with DES in CBC mode
01-05-2006, 02:24 PM #1
- Join Date
- Jan 2006
- Oslo, Norway
- Thanked 0 Times in 0 Posts
Crypting with DES in CBC mode
Is this algorithm difficult to implement in PHP code?
1. Concatenate the username and the password to produce a plaintext string;
2. Convert the plaintext string to uppercase characters;
3. Convert the plaintext string to multi-byte storage format; ASCII
characters have the high byte set to 0x00;
4. Encrypt the plaintext string (padded with 0s if necessary to the
next even block length) using the DES algorithm in cipher block
chaining (CBC) mode with a fixed key value of 0x0123456789ABCDEF;
5. Encrypt the plaintext string again with DES-CBC, but using the
last block of the output of the previous step (ignoring parity
bits) as the encryption key. The last block of the output is
converted into a printable string to produce the password hash
(Point 1 and 2 is, of course, not THAT difficult )
I came so far:
$chiper = MCRYPT_3DES;
$key1 = ?; //What is this?
$data = "USERNAMEPASSWORD"; // (How to fix this acording to point 3 in the algorithm?)
$mode = MCRYPT_MODE_CBC;
$iv = ?; //: What is this?
// First time encryption
$res1 = mcrypt_encrypt($chiper, $key1, $data, $mode, $iv);
// Get the last block to use as key in second encryption
$last_block1 = substr($res1, strlen($res1)-8, 8);
// Second time encryption
$res2 = mcrypt_encrypt($chiper, $last_block1, $data, $mode, $iv);
// Then get the last block of $res2 and convert to hex
$last_block2 = substr($res2, strlen($res2)-8, 8);
$hash = bin2hex($last_block2);
Last edited by jskaar; 01-07-2006 at 12:45 AM.