无法在LINQ to SQL中将类型'string'隐式转换为'System.Data.Linq.Binary

use*_*206 1 c# database hash linq-to-sql

我已经对密码进行了哈希,然后我将其插入到数据库中,但问题是每次我尝试执行此查询时都会发生这种情况

Cannot implicitly convert type 'string' to 'System.Data.Linq.Binary'
Run Code Online (Sandbox Code Playgroud)

在我的数据库表中,accnt_pass是Binary(50),这是我的代码

//Instantiate a new Hasher Object
var hasher = new Hasher();

hasher.SaltSize = 16;

//Encrypts The password
var encryptedPassword = hasher.Encrypt(txtPass.Text);

Account newUser = new Account();

newUser.accnt_User = txtUser.Text;
newUser.accnt_Position = txtPosition.Text;
newUser.accnt_Pass = encryptedPassword; 
Run Code Online (Sandbox Code Playgroud)

我正在使用Encrypto进行散列,

Rom*_*ter 6

如果sql列是二进制类型,则需要将字符串encryptedPassword转换为字节数组.而不是线

newUser.accnt_Pass = encryptedPassword;
Run Code Online (Sandbox Code Playgroud)

System.Text.UTF8Encoding encoding=new System.Text.UTF8Encoding();
newUser.accnt_Pass = new System.Data.Linq.Binary(encoding.GetBytes(encryptedPassword));
Run Code Online (Sandbox Code Playgroud)