Encrypt String in .NET Core

后端 未结 6 1949
Happy的楠姐
Happy的楠姐 2020-12-24 13:50

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 decr

6条回答
  •  抹茶落季
    2020-12-24 14:21

    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.

    The symmetric encryption options available in .NET Core are:

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

    And for asymmetric encryption

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

    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.

提交回复
热议问题