Created
May 13, 2014 09:07
-
-
Save qex/0632281caaaa3bb2a163 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function encrypt( $source, $key ) { | |
/* calculate padding ... */ | |
$pad = 8 - ( strlen( $source ) % 8 ); | |
/* encrypt using MCrypt ... */ | |
return base64_encode( mcrypt_encrypt( | |
MCRYPT_DES ,$key, $source . str_repeat( chr( $pad ), $pad ), | |
MCRYPT_MODE_CBC, pack( | |
'c8', 1, 2, 3, 4, 5, 6, 7, 8 | |
) ) ); | |
} | |
/* max length of key is 8 ... any longer is useless ... */ | |
assert( true, 'sWql7JYSxGRhqgjOfx+9gQ==' == | |
encrypt( '371325751788249', 'SpanDivA' ) | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment