无法将类型字符串隐式转换为byte [] [英] Cannot implicitly convert type string to byte[]

查看:231
本文介绍了无法将类型字符串隐式转换为byte []的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个类用加密的哈希加密密码。

I have a class that encrypts a password with a salted hash.

但是如果我想传递一个null类,我得到以下错误:不能将类型字符串隐式转换为byte []

But If I want to pass a null to the class I get the following error: Cannot implicitly convert type string to byte[]

这里是类代码:

public class MyHash
{
    public static string ComputeHash(string plainText, 
                            string hashAlgorithm, byte[] saltBytes)
    {
        Hash Code
    }
}

我收到错误:不能隐式转换类型字符串为byte []

When I use the class I get the error: "Cannot implicitly convert type string to byte[]"

//Encrypt Password
byte[] NoHash = null;
byte[] encds = MyHash.ComputeHash(Password, "SHA256", NoHash);


推荐答案

ComputeHash函数的返回类型是一个字符串。您尝试将函数的结果分配给encds,这是byte []。编译器将这个差异指向你,因为没有从string到byte []的隐式转换。

The return type of your ComputeHash function is a string. You try to assign the result of your function to encds, which is byte[]. The compiler points this discrepancy out to you, because there is no implicit conversion from string to byte[].

这篇关于无法将类型字符串隐式转换为byte []的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆