Tag Archives: Rsa

[Solved] RSA encryption request error: javax.crypto.badpaddingexception: decryption error

📖 Abstract


Share today — RSA encryption request error: javax. Crypto. Badpaddingexception: decryption error , welcome to pay attention!

Read related articles: spring boot + security based on the separation of the front and back RSA password encryption login process


🌂 resolvent

In the login method, the space can be replaced by a + sign, just ask if you want to be coquettish

String inputDecryptData = "";
        try {
            Object privateKey = redisUtil.get(Constant.RSA_PRIVATE_KEY);

            inputDecryptData =  RSAUtils.decrypt(password.replaceAll(" ","+"), RSAUtils.getPrivateKey(privateKey.toString()));
        } catch (Exception e) {
            log.error("RSA encryption and decryption exceptions occurred ======>", e);
            throw new BizException("RSA encryption and decryption exception occurred");
        }

Finally, thank you for watching patiently, leaving a like collection is your greatest encouragement to me!

Analysis and solution of RSA premaster secret error

Problem description
Java is packaged and runs with Java-XMx1g-java.ext.dirs =lib2 Runner XX.
error: RSA premaster secret error
test has no problem, it can run locally and the result is correct; The server can run, but the results are incorrect. Report the above error.
Problem analysis
Java-cp XX. Jar YY is operational.
java-djava.ext.dirs will not run.
After java-java.ext.dirs loads the Lib, the JAR package under %JAVA_HOME%\ jRE \ Lib \ext will not load.
is queried, involving sunjce_provider.jar.
Solution 1
Find Sunjce, copy it to lib, and run the solution.

echo $JAVA_HOME  
> find $JAVA_HOME -iname "*sunjce*jar"   # find sunjce
/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/ext/sunjce_provider.jar

Just copy this into lib.
Solution 2
You just have to load the JAR package under Ext, otherwise it’s a problem.
for example: java-java.ext.dirs =lib:$JAVA_HOME/jre/lib/ ext-jar build/ myappjar.jar
conclusion

    cp makes use of the current jar package and the lib/ext directory jar package in the jre, -d does not. Copy the past jar

if necessary
Refer to the reference
https://stackoverflow.com/questions/21390157/rsa-premaster-secret-error