I am trying to use a Cipher
with an RSA key pair along with the "AndroidKeyStore"
. In all of the Android documentation I can find, the examples show Cipher.getInstance("RSA/ECB/OAEPWithSHA-256AndMGF1Padding")
or Cipher.getInstance("RSA/ECB/PKCS1Padding")
. Both of which come up with the same warning on Android Studio:
ECB Encryption should not be used
Cipher#getInstance should not be called with ECB as the cipher mode or without setting the cipher mode because the default mode on android is ECB, which is insecure.
Obviously I cannot omit it, or set the mode to None
, because the default is ECB. If ECB mode is insecure, which mode should I be using?
If I use any other mode (that I know of) I get a NoSuchAlgorithmException: No provider found for RSA/{mode}/OAEPWithSHA-256AndMGF1Padding
. Could the padding be the problem?
Either way, according to the Android KeyStore System documentation, ECB mode seems to be the only cipher block mode that it supports while using RSA.