Skip to content

Instantly share code, notes, and snippets.

Created May 5, 2011 15:45
Show Gist options
  • Select an option

  • Save anonymous/957281 to your computer and use it in GitHub Desktop.

Select an option

Save anonymous/957281 to your computer and use it in GitHub Desktop.

Revisions

  1. @invalid-email-address Anonymous created this gist May 5, 2011.
    11 changes: 11 additions & 0 deletions gistfile1.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,11 @@
    function aes256EcbPkcs7PaddingEncrypt($key, $data) {
    $padding = 16 - (strlen($data) % 16);
    $data .= str_repeat(chr($padding), $padding);
    return mcrypt_encrypt(MCRYPT_RIJNDAEL_128, hash('SHA256', $key, true), $data, MCRYPT_MODE_ECB);
    }

    function aes256EcbPkcs7PaddingDecrypt($key, $data) {
    $data = mcrypt_decrypt(MCRYPT_RIJNDAEL_128, hash('SHA256', $key, true), $data, MCRYPT_MODE_ECB);
    $padding = ord($data[strlen($data) - 1]);
    return substr($data, 0, -$padding);
    }