我在加密数据时遇到非法blocksize异常。该代码用于使用指纹身份验证进行加密和解密。 错误日志:
06-16 12:21:51.267:D / ResourcesManager(19796):对于用户0,新的叠加取出Null 06-16 12:21:51.297:W / System.err(19597):javax.crypto.IllegalBlockSizeException 06-16 12:21:51.297:W / System.err(19597):在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
代码:
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());