douke6881
douke6881
2011-10-31 22:51

快速PHP加密算法? [关闭]

已采纳

im currently implementing a security module in a voting system and i was wondering what is the fastest way to encrypt (not hash) data in php? I was thinking something something like TEA, but i've never really tested the performance. I would really appreciate if someone share some know-how here.

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

1条回答

  • duandi4238 duandi4238 10年前

    My suggestion is PHP's mcrypt module: http://php.net/manual/en/book.mcrypt.php

    Code sample:

    // encrypt
    $data = 'data to encrypt';
    $key = 'mykey';
    $vector_size = mcrypt_get_iv_size( MCRYPT_TRIPLEDES, MCRYPT_MODE_NOFB );
    $encrypted_data = mcrypt_encrypt( MCRYPT_TRIPLEDES, substr( sha1( $key ), -9 ), $data, MCRYPT_MODE_NOFB, $vector_size );
    
    // decrypt
    $key = 'mykey';
    $vector_size = mcrypt_get_iv_size( MCRYPT_TRIPLEDES, MCRYPT_MODE_NOFB );
    $decrypted_data = rtrim( mcrypt_decrypt( MCRYPT_TRIPLEDES, substr( sha1( $key ), -9 ), $encrypted_data, MCRYPT_MODE_NOFB, $vector_size ), "\0" );
    
    点赞 评论 复制链接分享

相关推荐