How to create a system for migrating encryption?

I want to configure a system where I can transfer an encrypted password (hash password) from one system to another. How can I do it?

Say 2 months on the line, I found encryption that is 10 times better, and the current hash function has been proven without a doubt, completely vulnerable. How do I switch to transferring a user's password from one type of hash to another (best).

+4
source share
4 answers

You can slowly move from a method to another using the following technique. I can’t guarantee its quality, so please take it with salt (no pun intended).

For example, consider the following table in which users are stored:

id name password salt hashmethod -------------------------------------------- 1 alice ABC52... ABD... md5 2 bob 28DHF... Z+d... sha1 ... 

Say your obsolete hash method is md5 and you want to replace it with safer sha1 , this is what you do:

  • The user logs in, you use your password with the new method (sha1) and salt.
    • a) If a match is found (the corresponding username and password and the sha1 method), the user logs in.
    • b) If no match is found:
      • 1) You use a hash with the old method (md5) and salt.
        • a) If a match is found (the corresponding username and password and the md5 method), you enter the password with the new method (sha1) and salt and update the database accordingly. The user is registered.
        • b) If no match is found, the credentials are invalid and the user is not logged in.

This migration can take a lot of time, therefore, in order to speed it up, you should send an email to your users with a request to enter the system or change their passwords.

Hope this helps.

+5
source

In general, you cannot. You cannot recover passwords from hashes; that the whole hash point. If the original hash function was so broken that you can recover the passwords, then you can just do it and then use them with the new function.

+1
source

Typically, you do the following:

1) You create a public / private key pair, usually using RSA.

2) You carefully protect the private key. You never, never store it online. (You might want to split it in half and trust other people. You might want to use secret secret access. You might want to protect it in a token.)

3) Each time you store a password, you also keep a copy encrypted with the public key.

4) If in the future you need to recover passwords with clear text, you will restore the secret key and decrypt the saved copies of passwords.

Please note that this is a technical description of how you do this. How you do it safely , is difficult and depends on your specific situation. For example, you should consider threat models in which an attacker replaces your public key with his own.

+1
source

This only applies to systems that use a one-way hash method to store passwords and compare authentication hashes.

If your system requires such an update, I would do the following.

As Taimon noted, hashing is one way and you cannot extract the source text from the hash.

In my database table storing user information and password, I would include an integer Hash level field. This indicates which hash method the user is using.

When a system is added with a new hashing method, the maximum hashing level will be increased.

Say if I already have 2 hashing methods

 1 MD5 2 SHA1 3 SHA256 

If I add a new SHA512 hashing method, it will become

 4 SHA512 

Each time a user logs in, the system checks to see if the user password matches the name in the database using the identified Hashing level. There are several cases here:

  • If the password hashes match, but the User Hashing level is not the highest Hashing level that the system offers, then the hash enter the user password, that is, plain text using the highest level of the hashing method and set the Hashing level from the user to the highest Hashing level. Then the user authenticates.
  • If the password hashes match and the User Hash level is the highest Hash level, then the user is authenticated.
  • If the password hashes do not match at all, the user is denied.

This means that whenever you update the hash level of the system, the user password is updated to the highest level at the next authentication.

0
source

Source: https://habr.com/ru/post/1388792/


All Articles