'Decrypt AES/CBC/PKCS5Padding in Rhino JS

I am trying to decrypt the below value in my js script. The engine is Rhino javascript 1.7.13.

"{$crypto={type=x-simple-encryption, value={cipher=AES/CBC/PKCS5Padding, stableId=openidm-sym-default, salt=MQja0/re0ddXVHf3Pf58pw==, data=g6D0VXvFWO9Qps6LG09lA3D0q4RA3GiRPRHxGXZem0oRStkxXOEgg0XELZgRgCmd, keySize=16, purpose=idm.password.encryption, iv=6QcQD7WcXvVT3IkzSuX6Cg==, mac=HRqJ4zkL12coq3VU/q9W9g==}}}"

The expected decrypt value is below.

{SHA}6QFhU67ig5W6XPTzQbBT/7raZIo=

Is there a way in Rhino we can achieve this? Any api we can utilise for this purpose.



Solution 1:[1]

Rhino doesn't offer any specific api's for cryptography: Rhino is a JavaScript engine and as such exposes standard JavaScript APIs.

Depending on how you're using Rhino, you can interact with available Java classes. So you need to look at how you can achieve what you need using Java and then, from JavaScript invoke the required Java apis

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Paul