Importing CryptoJS library in Apigee Saas

Hi Team,

We have a requirement of hashing msg for digest, before applying HMAC policy,  wanted to do in java script using  sha512() and hash() which are part of CryptoJS library.

please suggest a best way to achieve this.

Thanks

 

Solved Solved
0 1 78
1 ACCEPTED SOLUTION

You don't need JavaScript and you don't need CryptoJS to do that in Apigee. 

You can do what you describe using an AssignMessage policy and message templates. For example

<AssignMessage name='AM-compute-hash'>
  <!-- non-keyed hash -->
  <AssignVariable>
    <Name>hashed</Name>
    <Template>{sha512Hex(request.content)}</Template>
  </AssignVariable>
  <!-- keyed hash -->
  <AssignVariable>
    <Name>hmac_value</Name>
    <Template>{hmacSha512(encodedkey,request.content,'base16')}</Template>
  </AssignVariable>
</AssignMessage>

For more on this, check the relevant documentation.

 If you still want to use JavaScript, you can use the builtin crypto object, rather than importing CryptoJS.  

I do not advise that you use the CryptoJS module within Apigee.  If you insist, you will need to "browserify" it in order to allow it to run within the Rhino engine.  It will be slow.  Also as I explained, it's unnecessary.

View solution in original post

1 REPLY 1

You don't need JavaScript and you don't need CryptoJS to do that in Apigee. 

You can do what you describe using an AssignMessage policy and message templates. For example

<AssignMessage name='AM-compute-hash'>
  <!-- non-keyed hash -->
  <AssignVariable>
    <Name>hashed</Name>
    <Template>{sha512Hex(request.content)}</Template>
  </AssignVariable>
  <!-- keyed hash -->
  <AssignVariable>
    <Name>hmac_value</Name>
    <Template>{hmacSha512(encodedkey,request.content,'base16')}</Template>
  </AssignVariable>
</AssignMessage>

For more on this, check the relevant documentation.

 If you still want to use JavaScript, you can use the builtin crypto object, rather than importing CryptoJS.  

I do not advise that you use the CryptoJS module within Apigee.  If you insist, you will need to "browserify" it in order to allow it to run within the Rhino engine.  It will be slow.  Also as I explained, it's unnecessary.