0

I am getting illegalblocksize exception while encrypting data. The code is for encryption and decrpting using fingerprint authentication. Error logs:

06-16 12:21:51.267: D/ResourcesManager(19796): For user 0 new overlays fetched Null 06-16 12:21:51.297: W/System.err(19597): javax.crypto.IllegalBlockSizeException 06-16 12:21:51.297: W/System.err(19597): at android.security.keystore.AndroidKeyStoreCipherSpiBase.engineDoFinal(AndroidKeyStoreCipherSpiBase.java:486) 06-16 12:21:51.297: W/System.err(19597): at javax.crypto.Cipher.doFinal(Cipher.java:1502) 06-16 12:21:51.297: W/System.err(19597): at com.example.u29692.fingptsample.MainActivity.saveUserPin

code:

 try {
            Log.e("ifbb", "body saveUserPin ");
            SecretKey secretKey = createKey();
            Cipher cipher = Cipher.getInstance(TRANSFORMATION);
            cipher.init(Cipher.ENCRYPT_MODE, secretKey);
          byte[] encryptionIv = cipher.getIV();
            Toast.makeText(this, "b4dofinal", Toast.LENGTH_LONG).show();
             byte[] passwordBytes = new byte[0];

            try {
                passwordBytes = pin.getBytes(CHARSET_NAME);
                Toast.makeText(this, "value1" + passwordBytes, Toast.LENGTH_LONG).show();
              Log.e("ifbb", "body passwordBytes " + passwordBytes);
            } catch (UnsupportedEncodingException e) {
                Log.e("ifbb", "body UnsupportedEncodingException " + e.toString());
                Toast.makeText(this, "UnsupportedEncodingException" + passwordBytes, Toast.LENGTH_LONG).show();
                e.printStackTrace();
            }


            byte[] encryptedPasswordBytes = cipher.doFinal(pin.getBytes());
ruby
  • 147
  • 2
  • 3
  • 13
  • As per the logs issue is happening while performing dofinal. – ruby Jun 16 '17 at 08:15
  • The code is taken from the below link: https://stackoverflow.com/questions/40724749/how-to-get-key-from-keystore-on-successful-fingerprint-auth/44583756#44583756 – ruby Jun 16 '17 at 09:53

0 Answers0