note 68368 added to function.mcrypt-encrypt
| From: | ale_ferrer at yahoo dot com | Date: | Mon, 24 Jul 2006 21:35:45 +0000 |
| Subject: | note 68368 added to function.mcrypt-encrypt | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-115105@lists.php.net to get a copy of this message | ||
Mcript - Dot NET - 3DES problem.
This is a solution for the 3DES algorithm's problem in his interaction with .NET
TripleDESCryptoServiceProvider (System.Security.Cryptography), CBC mode, because the key is
completed to 192bits and the text is padded.
So, we has two problems:
- The key's completion was posted by "jesse at pctest dot com".
- The text padding also posted by him, but the completion is a little different. The
padding bytes are 0x01 to 0x08 because completed to 8 bytes blocks. If your text have a whole number
of 8 bytes blocks, the algorithm add other block with padded bytes (0x08).
This is a function to encrypt a text in a equal form that the Dot NET algorithm:
<?PHP
function encryptNET3DES($key, $vector, $text){
$td = mcrypt_module_open (MCRYPT_3DES, '', MCRYPT_MODE_CBC, '');
// Complete the key
$key_add = 24-strlen($key);
$key .= substr($key,0,$key_add);
// Padding the text
$text_add = strlen($text)%8;
for($i=$text_add; $i<8; $i++){
$text .= chr(8-$text_add);
}
mcrypt_generic_init ($td, $key, $vector);
$encrypt64 = mcrypt_generic ($td, $text);
mcrypt_generic_deinit($td);
mcrypt_module_close($td);
// Return the encrypt text in 64 bits code
return $encrypt64;
}
?>
----
Server IP: 201.216.232.3
Probable Submitter: 157.92.4.2 (proxied: 157.92.50.233, 157.92.49.2)
----
X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER
autolearn=no version=2.64
----
Manual Page -- http://www.php.net/manual/en/function.mcrypt-encrypt.php
Edit -- http://master.php.net/note/edit/68368
Del: integrated -- http://master.php.net/note/delete/68368/integrated
Del: useless -- http://master.php.net/note/delete/68368/useless
Del: bad code -- http://master.php.net/note/delete/68368/bad+code
Del: spam -- http://master.php.net/note/delete/68368/spam
Del: non-english -- http://master.php.net/note/delete/68368/non-english
Del: in docs -- http://master.php.net/note/delete/68368/in+docs
Del: other reasons-- http://master.php.net/note/delete/68368
Reject -- http://master.php.net/note/reject/68368
Search -- http://master.php.net/manage/user-notes.php