crypto functions in apigee javascript policy

Hi,
 
What is the easiest way convert this nodejs code using the builtin crypto package into an Apigee policy (preferably javascript)
 

 

const crypto=require('crypto');
const value = "stringtohash";
const hash = crypto.createHash('sha256').update(value).digest('hex');
const salt = "somlargevaluerepresentingthesalt";
const pbkHash = crypto.pbkdf2Sync(value, salt, 100000, 32, 'sha256').toString('hex');

 

 
hash and pbkHash would be available as context variables for subsequent policies.
 
Thanks.
 
 
 
Solved Solved
0 4 232
1 ACCEPTED SOLUTION

The JS policy supports a crypto class, which, contrary to its name, does hashing. Read about it here.

There is no PBKDF2 available in the Apigee Javascript policy. 

What are you really trying to do?  I know what a PBKDF2 does.  I want to know why you are planning to use Apigee to invoke PBKDF2. Can you give me some broader context, and maybe we can explore options.

 

View solution in original post

4 REPLIES 4

The JS policy supports a crypto class, which, contrary to its name, does hashing. Read about it here.

There is no PBKDF2 available in the Apigee Javascript policy. 

What are you really trying to do?  I know what a PBKDF2 does.  I want to know why you are planning to use Apigee to invoke PBKDF2. Can you give me some broader context, and maybe we can explore options.

 

Thanks @dchiesa1 . There are several backend api's expecting a secret value persisted in PBKDF2 format, as these apis are all behind Apigee proxies, i'm trying to create a shared flow that does the hashing in Apigee and forwarding the hashes to the target invocations.

I'm curious, what are these services? I don't know of too many APIs that expect application credentials in the form of PBKDF2 keys.  Can you tell me more?

Certain values in the database are persisted as PBKDF2 hashes, i'm not sure why. The services themselves are multiplatform and are performing the hashes themselves. I want to move the hashing to the Apigee , and pass the hashed value to the services. In apigee i can cache the hashes making it more efficient to pass around.