Programmers learn & share
0 votes
97 views

Problem :

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

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

by (6.9k points)   | 97 views

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

by (36.1k points)  
edited by
2,187 questions
2,514 answers
59 comments
241 users