Decrypting bytes encrypted by .NET's RijndaelManaged using Java

后端 未结 1 748
失恋的感觉
失恋的感觉 2021-02-06 14:33

I am trying to decrypt something, which was encrypted using RijndaelManaged of .NET/C#, using Java to decrypt.

The C# program is not mine; I cannot change it to be more

相关标签:
1条回答
  • 2021-02-06 15:11

    It's possible using the standard AES decryption. Rijndel is just a superset of AES which is more lax with particular options. See Rijndael support in Java for more details.

    From the answer given in the linked question:

    byte[] sessionKey = null; //Where you get this from is beyond the scope of this post
    byte[] iv = null ; //Ditto
    byte[] plaintext = null; //Whatever you want to encrypt/decrypt
    Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
    //You can use ENCRYPT_MODE or DECRYPT_MODE
    cipher.calling init(Cipher.DECRYPT_MODE, new SecretKeySpec(sessionKey, "AES"), new IvParameterSpec(iv));
    byte[] ciphertext = cipher.doFinal(plaintext);
    
    0 讨论(0)
提交回复
热议问题