我有以下需要翻译成 c# 的 Java 代码:
public static byte[] encryptAES(byte[] toEncrypt, byte[] key,
boolean encrypte) throws Exception {
Security.addProvider(new BouncyCastleProvider());
byte[] iv = { (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00 };
IvParameterSpec salt = new IvParameterSpec(iv);
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding", "BC");
if (encrypte == false)
cipher.init(Cipher.DECRYPT_MODE, new SecretKeySpec(key, "AES"), salt);
else
cipher.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(key, "AES"), salt);
byte[] result = cipher.doFinal(toEncrypt);
return result;
}
你如何做相当于:
Security.addProvider(new BouncyCastleProvider());
什么是等价的:
IvParameterSpec salt = new IvParameterSpec(iv);
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding", "BC");