PHP's des encryption + ECB mode + PKCS5 complement ***** encryption function * algorithm: des * encryption mode: ecb * completion method: PKCS5 ** @ paramunknown_type $ input * functionencryptDesEcbPKCS5 ($ input, $ key) {$ sizemcrypt_get_ B PHP's des encryption + ECB mode + PKCS5 complete
/* Encryption function * algorithm: des * encryption mode: ecb * completion method: PKCS5 ** @ param unknown_type $ input */function encryptDesEcbPKCS5 ($ input, $ key) {$ size = mcrypt_get_block_size ('Des ', 'ECB'); $ input = pkcs5_pad ($ input, $ size); $ td = mcrypt_module_open ('Des ','', 'ECB ', ''); // $ iv = mcrypt_create_iv (mcrypt_enc_get_iv_size ($ td), MCRYPT_RAND); $ iv = 0; mcrypt_generic_init ($ td, $ key, $ iv); $ data = mdecrypt_generic ($ td, $ Indium Ut); mcrypt_generic_deinit ($ td); mcrypt_module_close ($ td); // $ data = base64_encode ($ data); return $ data;}/*** decryption function * algorithm: des * encryption mode: ecb * completion method: PKCS5 * @ param unknown_type $ input */function decryptDesEcbPKCS5 ($ input, $ key) {$ size = mcrypt_get_block_size ('Des ', 'ECB '); $ td = mcrypt_module_open ('Des', '', 'ECB ',''); $ iv = 0; mcrypt_generic_init ($ td, $ key, $ iv); $ data = mcrypt_generic ($ td, $ input); Mcrypt_generic_deinit ($ td); mcrypt_module_close ($ td); $ data = pkcs5_unpad ($ data, $ size); // $ data = base64_encode ($ data ); return $ data;} function pkcs5_pad ($ text, $ blocksize) {$ pad = $ blocksize-(strlen ($ text) % $ blocksize); return $ text. str_repeat (chr ($ pad), $ pad);} function pkcs5_unpad ($ text) {$ pad = ord ($ text {strlen ($ text)-1 }); if ($ pad> strlen ($ text) return false; if (strspn ($ text), Chr ($ pad), strlen ($ text)-$ pad )! = $ Pad) return false; return substr ($ text, 0,-1 * $ pad);} $ str = 'Test Crypt'; $ key = 'jack11 '; $ res = encryptDesEcbPKCS5 ($ str, $ key); echo "$ res \ n"; $ deRes = decryptDesEcbPKCS5 ($ res, $ key ); echo "\ n $ deRes \ n ";
?
Php des encryption is special and cannot be specified.
Http://www.herongyang.com/Cryptography/DES-PHP-Block-Padding-in-mcrypt.html