更新:问题是我!我犯了一个错误,否则两个 Cods(下面和PS上的那个都是正确的)但仍然感谢 @Luke Park 的精彩回答,我学到了一些新东西。
我对加密/解密算法不熟悉,因此我在网上搜索并找到了这个类:
代码是:(我在Decrypt方法中添加了一个 Try/Catch,以防密码错误return "";)
using System;
using System.Text;
using System.Security.Cryptography;
using System.IO;
using System.Linq;
namespace EncryptStringSample
{
public static class StringCipher
{
// This constant is used to determine the keysize of the encryption algorithm in bits.
// We divide this by 8 within the code below to get the equivalent number of bytes.
private const int Keysize = 256;
// This constant …Run Code Online (Sandbox Code Playgroud)