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());