Skip to content

Instantly share code, notes, and snippets.

@qex
Created May 13, 2014 09:07
Show Gist options
  • Save qex/0632281caaaa3bb2a163 to your computer and use it in GitHub Desktop.
Save qex/0632281caaaa3bb2a163 to your computer and use it in GitHub Desktop.
<?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