Community articlehash method
Added by IBM contributorIBM on May 2, 2012
Rate this article 1 starsRate this article 2 starsRate this article 3 starsRate this article 4 starsRate this article 5 stars

No abstract provided.


This method hashes a message using the hashing algorithm of your choice.


   public byte  [] hash(
      byte  [] theMessage
      ) throws UWIException;


Table 1. hash parameters
theMessagebyte[]The message you want to hash.


A hashed message, or throws a generic exception (UWIException) if an error occurs.


The following example uses getSignature to get the signature object from the signature node, and uses getDataByPath to get the signer's identity from the signature object. It then retrieves the signer's shared secret from a database, and hashes that secret using the hash method. Next, it calls validateHMACWithHashedSecret to validate the signature.
   public short checkSignature(FormNodeP theSignatureNode, Certificate 
      theServerCert, Hash theHashObject)
   Signature theSignatureObject;
   byte [] theSecret;
   byte  [] hashedSecret;
   String signerCommonName;
   BooleanHolder encodedData;
   IntHolder theStatus;
   short validation;
      theSignatureObject = theSignatureNode.getSignature();
      encodedData = new BooleanHolder();
      if ((signerCommonName = theSignatureObject.getDataByPath(
         "SigningCert: Subject: CN", false, encodedData)) == null)
         throw new UWIException("Could not determine signer's name.");
      /* Include external code that matches the signer's identity to a 
         shared secret and sets theSecret to match.  This is most likely a 
         database lookup. */
      hashedSecret = theHashObject.hash(theSecret);
      theStatus = new IntHolder();
      validation = theSignatureNode.validateHMACWithHashedSecret(
         hashedSecret, theServerCert, theStatus);
      /* Check the status in case the process required user input. */
      if (theStatus.value != SecurityUserStatusType.SUSTATUS_OK)
         throw new UWIException("Validation required user input.");

Parent topic:
Hash class