3
我想在sqlite數據庫中存儲登錄名和密碼。此數據庫使用SQLCipher庫加密。但是,加密數據庫的密碼是個別問題。該密碼存儲在應用程序代碼中。登錄和密碼由用戶提供以登錄到應用程序。在C#中有SHA256類。如果我足夠使用這個課程?或者,我應該使用散列和鹽或其他方法?在sqlite數據庫中加密登錄名和密碼 - C#中的SHA 256#
感謝
我想在sqlite數據庫中存儲登錄名和密碼。此數據庫使用SQLCipher庫加密。但是,加密數據庫的密碼是個別問題。該密碼存儲在應用程序代碼中。登錄和密碼由用戶提供以登錄到應用程序。在C#中有SHA256類。如果我足夠使用這個課程?或者,我應該使用散列和鹽或其他方法?在sqlite數據庫中加密登錄名和密碼 - C#中的SHA 256#
感謝
要在數據庫中存儲用戶密碼登錄的問題,您應該使用的哈希函數與鹽。
SHA 256
是其中之一,但有更好的存在。我建議你使用PBKDF2
派生函數。您可以使用.NET框架中提供的Rfc2898DeriveBytes
類實現自己的PBKDF2
哈希方法。
這裏是一個快速怎麼對做它:
int saltSize = 256; // Number of bytes of the salt
int iterations = 1000; // Number of times we iterate the function
// The more we iterate, the more it is gonna take time.
// The advantage of a great iterations number is to
// make brutforce attack more painful.
int hashSize = 20; // Number of bytes of the hash (the output)
var deriveBytes = new Rfc2898DeriveBytes("mypassword", saltSize, iterations);
byte[] salt = deriveBytes.Salt;
byte[] hash = deriveBytes.GetBytes(hashSize);
你必須現在來存儲鹽和數據庫中的哈希值。使用Convert.FromBase64String
和Convert.ToBase64String
從byte[]
獲得string
,反之亦然。
你應該散列+ salt用戶密碼。 – Nasreddine