Two-way encryption: I need to store passwords that can be retrieved

前端 未结 8 1152
滥情空心
滥情空心 2020-11-22 08:42

I am creating an application that will store passwords, which the user can retrieve and see. The passwords are for a hardware device, so checking against hashes are out of

8条回答
  •  孤街浪徒
    2020-11-22 09:43

    I'd only suggest public key encryption if you want the ability to set a user's password without their interaction (this can be handy for resets and shared passwords).

    Public key

    1. The OpenSSL extension, specifically openssl_public_encrypt and openssl_private_decrypt
    2. This would be straight RSA assuming your passwords will fit in key size - padding, otherwise you need a symmetric layer
    3. Store both keys for each user, the private key's passphrase is their application password

    Symmetric

    1. The Mcrypt extension
    2. AES-256 is probably a safe bet, but this could be a SO question in itself
    3. You don't - this would be their application password

    Both

    4. Yes - users would have to enter their application password every time, but storing it in the session would raise other issues

    5.

    • If someone steals the application data, it's as secure as the symmetric cipher (for the public key scheme, it's used to protect the private key with the passphrase.)
    • Your application should definitely be only accessible over SSL, preferably using client certificates.
    • Consider adding a second factor for authentication which would only be used once per session, like a token sent via SMS.

提交回复
热议问题