我正在使用IDataProtector在存儲到數據庫之前加密我的數據。所有字符串做工精細,例如:.net Core 2.0保護日期時間
LastName = _protector.Protect(student.LastName)
但是我不能使用保護:
public DateTime EnrollmentDate { get; set; }
使用:
Student nstudent = new Student
{
LastName = _protector.Protect(student.LastName),
EnrollmentDate = _protector.Protect(student.EnrollmentDate)
};
我得到這個錯誤:
cannot convert from 'System.DateTime' to 'byte[]'
DataProtector很簡單,它知道如何一個byte []進行加密。作爲*便利*有一個處理字符串的擴展方法。但這就是它結束的地方。如果你想利用它,你需要將DateTime轉換爲byte []。像BitConverter.GetBytes(dt.ToBinary())一樣。或者認爲加密日期沒有意義。 –