Search code examples
androidencryptionmd5message-digest

Can android throw NoSuchAlgorithmException for MD5


Android's MessageDigest page says MD5 is supported from day one - https://developer.android.com/reference/java/security/MessageDigest

But the MessageDigest.getInstance("MD5") method can throw NoSuchAlgorithmException and there is no getMD5Instance method which would have made it guaranteed. Is there any chance MD5 won't be available at least in newer android versions later than 23 (Marshmallow)? Thanks for replies.

There is another thread which discusses this but is 7 years old with some occurrences reported on android 2.x devices (Gingerbread). Is MD5 guaranteed to be available for use with MessageDigest in Android?


Solution

  • But the MessageDigest.getInstance("MD5") method can throw NoSuchAlgorithmException

    Correct. That is how the Java JDK defines MessageDigest. This class is not custom for the Android SDK.

    there is no getMD5Instance method which would have made it guaranteed

    Correct. Presumably, the JDK is set up to be able to discontinue obsolete algorithms in the future.

    Is there any chance MD5 won't be available at least in newer android versions later than 23 (Marshmallow)?

    It would surprise me if many current devices lack MD5 support. However:

    • With 26,000+ device models, and with device manufacturers that can do what they want, we cannot assume that everything supports MD5; and

    • We do not know what the future might bring — it is possible that MD5 will be removed for one reason or another