# AMI Security with Non-Python (Node.js)

**URL:** <https://community.shotgridsoftware.com/t/ami-security-with-non-python-node-js/10995>\
**Category:** Uncategorized\
**Created:** [December 10, 2020, 11:20pm UTC](https://community.shotgridsoftware.com/t/ami-security-with-non-python-node-js/10995 "2020-12-10T23:20:36Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![jimi](https://sea1.discourse-cdn.com/shotgunsoftware/user_avatar/community.shotgridsoftware.com/jimi/32/3575_2.png) [@jimi](https://community.shotgridsoftware.com/u/jimi)\
**Post date:** [December 10, 2020, 11:45pm UTC](https://community.shotgridsoftware.com/t/ami-security-with-non-python-node-js/10995/2 "2020-12-10T23:45:33Z")

</div>

I found this thread [AMI fails to validate from Media page](https://community.shotgridsoftware.com/t/ami-fails-to-validate-from-media-page/10739/5) which solved my issue.

The final working example is (NOTICE the `&& v`, and the `\r\n` movement, those were both needed!):

```
const key = 'my-key';

const sortedParams = [];
for (const [k, v] of Object.entries(form)) {
    if (k !== 'signature' && v) {
        sortedParams.push(`${k}=${v}\r\n`);
    }
}
sortedParams.sort();

const stringToVerify = sortedParams.join('');
console.log('stringToVerify:');
console.log(stringToVerify);

const signature = crypto.createHmac('sha1', key).update(stringToVerify).digest('hex');
app.log.info('signature (form):', form.signature);
app.log.info('signature (hmac):', signature);
```

---

_[View the full topic](https://community.shotgridsoftware.com/t/ami-security-with-non-python-node-js/10995)._
