行 - 我想通了,即使它欺骗到一个程度。因为我找不到任何与第三方提供的普通AES加密相匹配的加密技术,所以我要求他们将其更改为
Cipher cipher = Cipher.getInstance(“AES/CBC/PKCS5Padding”);
有了这个,我修改了我的C#代码,并最终得到了整合工作:
public static string Encrypt2(string plainText)
{
string PassPhrase = "somepassphrase";
string SaltValue = "somesalt";
int PasswordIterations = 0; //amend to match java encryption iteration
string InitVector = "someiv";
int KeySize = 0; //amend to match java encryption key size
byte[] initVectorBytes = Encoding.ASCII.GetBytes(InitVector);
byte[] saltValueBytes = Encoding.ASCII.GetBytes(SaltValue);
byte[] plainTextBytes = Encoding.UTF8.GetBytes(plainText);
Rfc2898DeriveBytes password = new Rfc2898DeriveBytes(
PassPhrase,
saltValueBytes,
PasswordIterations);
byte[] keyBytes = password.GetBytes(KeySize/8);
RijndaelManaged symmetricKey = new RijndaelManaged();
symmetricKey.Mode = CipherMode.CBC;
ICryptoTransform encryptor = symmetricKey.CreateEncryptor(
keyBytes,
initVectorBytes);
MemoryStream memoryStream = new MemoryStream();
CryptoStream cryptoStream = new CryptoStream(memoryStream,
encryptor,
CryptoStreamMode.Write);
cryptoStream.Write(plainTextBytes, 0, plainTextBytes.Length);
cryptoStream.FlushFinalBlock();
byte[] cipherTextBytes = memoryStream.ToArray();
memoryStream.Close();
cryptoStream.Close();
string cipherText = Convert.ToBase64String(cipherTextBytes);
return cipherText;
}