Page 1 of 1

How to get hash of message

Posted: Mon Oct 17, 2016 11:14 pm
by notuo
I tried to use MessageDigest to get hash. it always returned 6F 00. I guess MessageDigest.getInstance caused the problem, but I'm not sure. ANY HELP? tHANKS!

My sectional code:

Code: Select all

private void getDigest(byte[] buffer)
     {
          if (hashArray == null)
               hashArray = JCSystem.makeTransientByteArray((short)20, JCSystem.CLEAR_ON_DESELECT);
                   
          MessageDigest alg = MessageDigest.getInstance(MessageDigest.ALG_SHA,true);// If I comment this line, the applet can run w/o any problem.
                   
     }

Re: How to get hash of message

Posted: Tue Oct 18, 2016 3:39 am
by mabel
Use try/catch to find the reason.

Just like:

Code: Select all

try{
   MessageDigest alg = MessageDigest.getInstance(MessageDigest.ALG_SHA,true);
    }
catch(CryptoException e)
   {
     if ( e.GetReason() == CryptoException.NO_SUCH_ALGORITHM )
                           ISOException.throwIt( something );
   }

Re: How to get hash of message

Posted: Tue Oct 18, 2016 4:46 am
by Tarantino
MessageDigest.getInstance exception:
Throws:
CryptoException - with the following reason codes:
CryptoException.NO_SUCH_ALGORITHM if the requested algorithm or shared access mode is not supported.

So, you should make sure that that your card supports SHA.