Exception when calling MessageDigest.getInstance(“SHA256”)

前端 未结 2 2055
孤独总比滥情好
孤独总比滥情好 2021-02-04 02:02

I have code that works well on Android. When I ported it to my Windows 64-bit machine with JRE 1.6, the code did not work.

When I run the following line of code:

2条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-02-04 02:51

    When in doubt over what algorithms you can use for a JCA service, your first port of call should be the JCA Standard Algorithm Name Documentation. The algorithms guaranteed to be supported by the MessageDigest service in a JCA-compliant JVM are:

    • MD2
    • MD5
    • SHA-1
    • SHA-256
    • SHA-384
    • SHA-512

    It's common for providers to supply aliases for these algorithms, which is why it'd probably work with Bouncy Castle, but you should stick to these if you can to maximise portability.

    If you change your code to the following, it will work as expected:

    final MessageDigest digest = MessageDigest.getInstance("SHA-256");
    

提交回复
热议问题