在 .NET Core 中加密字符串 [英] Encrypt String in .NET Core

查看:47
本文介绍了在 .NET Core 中加密字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用密钥加密 .NET Core 中的字符串.我有一个客户端/服务器场景,想在客户端加密一个字符串,将它发送到服务器并解密它.

I would like to encrypt a string in .NET Core using a key. I have a client / server scenario and would like to encrypt a string on the client, send it to the server and decrypt it.

由于 .NET Core 仍处于早期阶段(例如 Rijndael 尚不可用),我有哪些选择?

As .NET Core is still in a early stage (e.g. Rijndael is not yet available), what are my options?

推荐答案

您真的不应该在 .NET 中使用 Rijndael/RijndaelManaged.如果您使用的 BlockSize 值为 128(这是默认值),那么您使用的是 AES,正如我 在类似的问题.

You really shouldn't ever use Rijndael/RijndaelManaged in .NET. If you're using it with a BlockSize value of 128 (which is the default) then you're using AES, as I explained in a similar question.

.NET Core 中可用的对称加密选项有:

The symmetric encryption options available in .NET Core are:

  • AES (System.Security.Cryptography.Aes.Create())
  • 3DES (System.Security.Cryptography.TripleDES.Create())

对于非对称加密

  • RSA (System.Security.Cryptography.RSA.Create())

特别是在 .NET Core 上,工厂是最好的方法,因为它们会返回一个在当前执行的操作系统上运行的对象.例如,RSACng 是一种公共类型,但仅适用于 Windows;RSAOpenSsl 是公共类型,但仅在 Linux 和 macOS 上受支持.

Especially on .NET Core the factories are the best way to go, because they will give back an object which works on the currently executing operating system. For example, RSACng is a public type but only works on Windows; and RSAOpenSsl is a public type but is only supported on Linux and macOS.

这篇关于在 .NET Core 中加密字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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