dongxie2613 2012-06-19 06:18
浏览 34
已采纳

加密到短串[关闭]

What encryption scheme returns a short string? I want a small result less than 32 characters. I also want to be able to decrypt it back to the original plaintext. The purpose is email verification, where the code is sent by email. When the code is received the user logs in into the site and enters the code (or clicks on the link).

EDIT: DECRYPTION is important as after verification i need to relate two non related records

Thanks

  • 写回答

5条回答 默认 最新

  • duanhui9840 2012-06-19 11:03
    关注

    You're talking about encryption but clearly need a hashing function. You can then relate the hash to any data model you want (whatever it is you want to 'encrypt' in this case) in a database. The hash is used like the key of a key-value store and can be completely random. The final size of an encryted string is always directly related to the size of the original string. Otherwise you're probably confusing hashes and encryption.

    So a simple use-case:

    • A user registers into a website.
    • The registration controller creates a new record into the 'pending_users' table which has only 2 columns: user_id and random_key.
    • And email is sent to the user containing the value of the random_key which is exposed as a link to verification.php?key=$random_key

    When the user executes the verification.php controller, the controller checks for the presence of the $random_key in the pending_users table. If found, it removes the record and changes a flag in the users table (active_account = true for example). If not found an error is sent back to the user.

    Hope this helps, Cheers

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化