正如我在这里看到的那样,有一种快速而简短的方法将向量转换为用c#中的字符分隔的字符串:
var result = string.Join(";", data);
var result = string.Join(";", data.Select(x => x.ToString()).ToArray());
Run Code Online (Sandbox Code Playgroud)
我想知道在c ++中是否有同样的方法来做到这一点?
我正在尝试使用加密字符串,RijndaelManaged以将其发送到第三方服务。我已经在旧版本的.Net Framework(4.5,4.6.x)中实现了该过程,如下所示:
RijndaelManaged rm= new RijndaelManaged();
rm.KeySize = 256;
rm.BlockSize = 256;//causes exception in dotnet core 2.1
rm.Padding = PaddingMode.PKCS7;
rm.Key = Convert.FromBase64String(this.Key);
rm.IV = Convert.FromBase64String(this.IV);
var encrypt = rm.CreateEncryptor(rm.Key, rm.IV);
Run Code Online (Sandbox Code Playgroud)
根据文档,RijndaelManaged可以与class一起使用BlockSize = 256。但是,当代码在dotenet core 2.1中运行时,会引发异常:
System.PlatformNotSupportedException:在此实现中,BlockSize必须为128。在System.Security.Cryptography.RijndaelManaged.set_BlockSize(Int32值)处
更新
感谢@拒绝访问的响应,根据这个,我已经注意到,它可能是DOTNET核心文档中了一个错误,我不能长期使用256 BlockSize与RijndaelManaged类。如前所述,加密的数据将被发送到第三方服务。我必须使用32长的Rijndael IV。我该如何处理?
我正在尝试将 settings.json 文件手动添加到 .net core 2.1 控制台应用程序。因此,我将这些 NuGet 包添加到项目中:
Microsoft.扩展.配置
Microsoft.Extensions.Configuration.FileExtensions
Microsoft.Extensions.Configuration.Json
appsettings.json并像这样创建文件:
{
"Section1": {
"Prop1": "value",
"Prop2": 300
}
}
Run Code Online (Sandbox Code Playgroud)
最后,我尝试从设置文件中获取值,如下所示:
var builder = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true);
_configuration = builder.Build();
var section = _configuration.GetSection("Section1");//section.Value is null
var test = _configuration.GetSection("Section1:Prop1");//it returns the proper value
var model = section as Section1Model;
Run Code Online (Sandbox Code Playgroud)
但是,section.Value是null,因此,model是null。如果我尝试获取类似的值,_configuration.GetSection("Section1:Prop1")它会返回正确的值。另外,如果我打电话_configuration.GetSection("Section1).GetChildren()它,它会返回一组设置。我做错了什么?
PS:我保证将设置文件复制到bin文件夹中