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

查看:500
本文介绍了在.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天全站免登陆