RSA .NET encryption Java decryption

后端 未结 3 1133
天命终不由人
天命终不由人 2020-12-23 12:41

I am trying to encrypt strings in .NET by using a RSA algorithm and decrypt the result in Java. At the moment, I have been able to do the opposite (Encrypt in Java, Decrypt

3条回答
  •  抹茶落季
    2020-12-23 13:18

    Here is the answer I couldn't post yesterday, related to the first answer to my post.

    Well, I have tested the code and I have some problems. I have tried not to change anything unless it was completely necessary. First I get an error here:

    Cipher rsaCipher = Cipher.getInstance(RSA_ALGORITHM, CRYPTO_PROVIDER);
    

    The "Entrust" crypto provider is not recognized... So I left just the first parameter. Then I get this error:

    javax.crypto.BadPaddingException: Data must start with zero
    

    I have tried through a WebService written in .NET which returns always byte arrays. Maybe there is some kind of problem in the translation. I know that I have to use Base64 numbers and (if I don't use AES) I have to break my Strings into pieces with the size of 128 bytes (limited by the RSA key). I am still working on the problem to realize why I could encrypt in Java and decrypt in .NET but not the opposite.

    Thanks again for your help!!

提交回复
热议问题