• Register
0 votes
156 views

Problem :

I am trying to implement password based encryption algorithm, but I get this 

javax.crypto.badpaddingexception: given final block not properly padded

6 5 3
6,930 points

Please log in or register to answer this question.

1 Answer

0 votes

Solution :

I had this issue due to my operating system, it is different to different platforms , its all about JRE implementation.

        new SecureRandom(key.getBytes())

will give the value in Windows, But it is different in Linux. So in Linux you need to change it to

        SecureRandom secureRandom = SecureRandom.getInstance("SHA1PRNG");
        secureRandom.setSeed(key.getBytes());
        kgen.init(128, secureRandom);

Further Readings:

https://github.com/nelenkov/android-backup-extractor/issues/46

9 7 4
38,600 points

Related questions

0 votes
2 answers 324 views
324 views
Problem : Today I installed Java 1.6.0.26 on my server user and when I try to run my application, I get the following exception. java.security.invalidkeyexception illegal key size or default parameters
asked Oct 23, 2019 peterlaw 6.9k points
0 votes
1 answer 2 views
2 views
Problem: The encryption works fine but when I try to decrypt, I get the following exception: Padding is invalid and cannot be removed
asked Apr 2 ummesalma 25.2k points
0 votes
1 answer 44 views
44 views
Problem : I am new to C#. I want to know how can I get the value of a given key in a following exception which I am currently facing in C# in a way it affects all the generic classes? Below is the exception which I am currently facing. "The given key was not present in the dictionary." How to fix above exception.
asked Feb 24, 2020 mphil 2.3k points
0 votes
1 answer 3 views
3 views
Problem: Every time I get this error > length of the data to decrypt is invalid
asked Apr 8 Azlan2020 2.3k points
0 votes
1 answer 3 views
3 views
Problrem: how to install ssl certificate in tomcat 7
asked Apr 6 Ifra 24.4k points
0 votes
0 answers 19 views
19 views
Problem: needed answer from expert? twrp asking password to decrypt data
asked Mar 7 bilal b 420 points
1 vote
1 answer 105 views
105 views
Problem : I am a Computer Science student. I am trying to learn Java Programming in this Covid19 lockdown period. I want to write a program which should perform the below task. “Write a java program to count number of characters in given string”. Please let me know the exact procedure to write the above mentioned program.
asked May 19, 2020 Martin K 6.6k points
0 votes
1 answer 3 views
3 views
Problem: I just can't understand how you convert something to one thing using some algorithm, and there is no way to convert it back using the algorithm in reverse. So how is this possible?
asked 5 days ago ummesalma 25.2k points
0 votes
1 answer 7 views
7 views
Problem: Any ideas on what I need to fix the error: could not find or load main class main caused by: java.lang.classnotfoundexception: main?
asked Mar 27 ashik 12.9k points
0 votes
1 answer 4 views
4 views
Problem: What are the effects of exceptions on performance in Java?
asked Mar 9 ummesalma 25.2k points