C#等效于AES的Java SecretKeySpec

我有以下用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);

以上是 C#等效于AES的Java SecretKeySpec 的全部内容, 来源链接: utcz.com/qa/435949.html

回到顶部