C# 相当于 AES 的 Java SecretKeySpec

C# equivalent of the Java SecretKeySpec for AES

我在 java 中编写了以下代码。为此,我需要等效的 C#。

Key key = new SecretKeySpec(keyValue, "AES");
Cipher c = Cipher.getInstance("AES");
c.init(1, key);
byte[] encVal = c.doFinal(Data.getBytes());
encryptedValue = new BASE64Encoder().encode(encVal);

此处的 C# 代码等效于 java。

System.Text.UTF8Encoding UTF8 = new System.Text.UTF8Encoding();
AesManaged tdes = new AesManaged();
tdes.Key = UTF8.GetBytes(keyValue);
tdes.Mode = CipherMode.ECB;
tdes.Padding = PaddingMode.PKCS7;
ICryptoTransform crypt = tdes.CreateEncryptor();
byte[] plain = Encoding.UTF8.GetBytes(text);
byte[] cipher = crypt.TransformFinalBlock(plain, 0, plain.Length);
String encryptedText = Convert.ToBase64String(cipher);