There are several levels of encryption you can use in Digest#SHA.
- Digest::SHA1.hexdigest() - produces a 40 characters of hexadecimal digits.
- Digest::SHA256.hexdigest() - produces a 64 characters of hexadecimal digits
- Digest::SHA384.hexdigest() - produces a 96 characters of hexadecimal digits
- Digest::SHA512.hexdigest() - produces a 128 characters of hexadecimal digits
You can check it by trying the following.
Note: To execute the commands, press Enter after typing.
- Open your console.
- Change the directory to any of your existing rails application.
- Type ruby script/console.
- Type a = Digest::SHA1.hexdigest(“test”).
- Type a.length. It will display the length of the strings in the variable a.
- Repeat step 4 but replacing SHA1 with SHA256, SHA384, or SHA 512.
Depending on your required level of security you can choose among the different SHA levels. If you require the highest level of encryption then you can use SHA512.
Most of its use include encrypting passwords before saving it to the database. You can also use it to encrypt files.
Peace!