RSA BadPaddingException : data must start with zero

后端 未结 2 1423
忘掉有多难
忘掉有多难 2021-01-01 06:55

I try to implement an RSA algorithm in a Java program. I am facing the \"BadPaddingException : data must start with zero\". Here are the methods used to encrypt and decrypt

2条回答
  •  天涯浪人
    2021-01-01 07:52

    So far, I've tracked this down to CipherSpi.engineDoFinal(). The explanation provided for BadPaddingException is

    [Thrown when the] cipher is in decryption mode, and (un)padding has been requested, but the decrypted data is not bounded by the appropriate padding bytes

    More specific behavior seems to be Spi-dependent. Do you know what Spi you're using? Just the default?

    EDIT: Unfortunately, I'm having a hard time tracking down what the default Spi is. It looks like it's chosen in Cipher.java's chooseFirstProvider() method, lines 644 to 721 here. If you have a debugger handy, you might want to find out what Spi you have, then check the documentation for it... but I still think it's more likely that something's going on with the input, not the logic (I asked about that earlier, in a comment).

提交回复
热议问题