0

I tried to run two examples cryptographic.

Doing debugging with emulators via eclipse everything works fine, debugging with the physical device I get an error:

pad block corrupted

the code is the same, I also tried to do

Cipher cipher = null;
cipher = Cipher.getInstance ("AES", "BC");

calling explicitly bouncy castle, it's OK on pc, error on the physical device I used these two examples

http://www.androidsnippets.com/encryptdecrypt-strings  http://www.techrepublic.com/blog/software-engineer/attention-android-developers-keep-user-data-safe/

can someone give me a hint? Thank you in advance

theonlygusti
  • 11,032
  • 11
  • 64
  • 119
gian82
  • 11
  • 3
  • Please post the stacktrace :) – Kevin Crain Feb 01 '15 at 11:02
  • To me at least, it's not entirely clear what you're asking - do you just want to know what the error means? How to stop it? Is it actually causing any other problems? What's the expected final outcome? – theonlygusti Feb 01 '15 at 11:14
  • I want to encrypt and decrypt string with a master password the code works fine on pc bad on the phone, I get an error (pad block corrupted) – gian82 Feb 01 '15 at 11:23
  • 1
    Are you using `SHA1PRNG` as per example? You can't use that because it is platform dependent. The are few posts in stackoverflow. [Encrypt/Decrypt String in Android and Java different values](http://stackoverflow.com/questions/9728538/encrypt-decrypt-string-in-android-and-java-different-values), Also, you can read this blog [Using Password-based Encryption on Android](http://nelenkov.blogspot.com/2012/04/using-password-based-encryption-on.html.) – Joey Chong Feb 01 '15 at 12:53
  • Ah, yes, that's the snippet that I'm fighting against since time began (because of the reason in that answer and a few of mine). If you use AndroidSnippets for your security, you may as well stop right there. – Maarten Bodewes Feb 01 '15 at 13:32
  • public byte[] keyWord=null; public TestCrypto() { this.keyWord=this.getKey(); } – gian82 Feb 01 '15 at 16:05
  • now code dont give me error ,no error on pc ,no error on device(4.4.2) but encrypted string result is different from pc to device(and start string of plain text is equal), someone can give me a link with deep explanation on aes on java, now i call getByte() only one time into constructor class before i have called one time for decrypt and one time for encrypt,i dont know how old code work on pc.. – gian82 Feb 01 '15 at 16:40

0 Answers0