1

I see some exceptions in production which only happens with some particular users (10 users for last month from 100 000+ active users per month)

My encrypt and decrypt methods uses the same algorithms and everything and all other users don't experience such issues

private byte[] encrypt(String cleartext) {
    final Cipher cipher = Cipher.getInstance("AES");
    cipher.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(secretKey, "AES"));
    return cipher.doFinal(cleartext.getBytes("UTF-8"));
}

private String decrypt(byte[] cipherbytes)  {
    final Cipher cipher = Cipher.getInstance("AES");
    cipher.init(Cipher.DECRYPT_MODE, new SecretKeySpec(secretKey, "AES"));
    return new String(cipher.doFinal(cipherbytes), "UTF-8");
}

private static String encode(byte[] input) {
    return Base64.encodeToString(input, Base64.NO_PADDING | Base64.NO_WRAP);
}

private static byte[] decode(String input) {
    return Base64.decode(input, Base64.NO_PADDING | Base64.NO_WRAP);
}

// these methods are exposed
String encryptAndEncodeMessage(String message) {
    return encode(encrypt(message))
}

String decryptAndDecodeMessage(String encodedEncryptedMessage) {
    return decrypt(decode(encodedEncryptedMessage))
}

secretKey is created only once and stored in shared prefs, so it is guaranteed to be the same

What can cause that exception to appear only for some users, and on soma particular devices? I see in logs only Huawei Mate 9 (MHA-L09) Android 7 and Huawei P20 Lite (ANE-LX1) Android 8

Could it be some kind of attempt to hack encrypted storage? Or some error in encrypting logic? I'm confused with small amount of such crashes, as if there was bug, it would affect bigger amount of users

Wackaloon
  • 2,285
  • 1
  • 16
  • 33

0 Answers0