[GH-ISSUE #794] Add Support for creating HmacSHA256 hashes #790

Open
opened 2026-03-03 19:21:54 +03:00 by kerem · 5 comments
Owner

Originally created by @nilayp on GitHub (Feb 19, 2021).
Original GitHub issue: https://github.com/ProxymanApp/Proxyman/issues/794

Originally assigned to: @NghiaTranUIT on GitHub.

Proxyman version? (Ex. Proxyman 1.4.3)

2.1.8

macOS Version? (Ex. mac 10.14)

10.15.17

Crypto-js supports creating Hmac256 and other keyed hashes. To use it (or the wide variety of HMAC hashes that can be done with Crypto-js, you just need to add a wrapper in the @addons/Crypto.js file. (~/Library/Application Support/com.proxyman.NSProxy/addons)

I added a constant declaration and an export like this:

const HmacSHA256 = (string, secret) => {
        return CryptoJS.HmacSHA256(string, secret);
}

exports.HmacSHA256 = HmacSHA256;

And it worked great. It sure would be nice to have this included in future versions.

Originally created by @nilayp on GitHub (Feb 19, 2021). Original GitHub issue: https://github.com/ProxymanApp/Proxyman/issues/794 Originally assigned to: @NghiaTranUIT on GitHub. ### Proxyman version? (Ex. Proxyman 1.4.3) 2.1.8 ### macOS Version? (Ex. mac 10.14) 10.15.17 Crypto-js supports creating Hmac256 and other keyed hashes. To use it (or the wide variety of HMAC hashes that can be done with Crypto-js, you just need to add a wrapper in the @addons/Crypto.js file. (~/Library/Application Support/com.proxyman.NSProxy/addons) I added a constant declaration and an export like this: ``` const HmacSHA256 = (string, secret) => { return CryptoJS.HmacSHA256(string, secret); } exports.HmacSHA256 = HmacSHA256; ``` And it worked great. It sure would be nice to have this included in future versions.
Author
Owner

@NghiaTranUIT commented on GitHub (Feb 20, 2021):

Thanks @nilayp I will add it to the next release 😄

<!-- gh-comment-id:782552059 --> @NghiaTranUIT commented on GitHub (Feb 20, 2021): Thanks @nilayp I will add it to the next release 😄
Author
Owner

@NghiaTranUIT commented on GitHub (Feb 20, 2021):

Added in this beta build: https://proxyman.s3.us-east-2.amazonaws.com/beta/Proxyman_2.18.0_Add_HmacSHA256.dmg

Changelogs

  • This build also converts the hashed data to a string
const HmacSHA256 = (string, secret) => {
    return String(CryptoJS.HmacSHA256(string, secret));
}

Notes

  • To get the latest addon, please delete ~/Library/Application Support/com.proxyman.NSProxy/addons/CryptoJS.js and relaunch the Beta build (This will be automatically done if I bump a new version in the next release, but for now, please do it manually 😄 )
<!-- gh-comment-id:782567347 --> @NghiaTranUIT commented on GitHub (Feb 20, 2021): Added in this beta build: https://proxyman.s3.us-east-2.amazonaws.com/beta/Proxyman_2.18.0_Add_HmacSHA256.dmg ### Changelogs - This build also converts the hashed data to a string ```js const HmacSHA256 = (string, secret) => { return String(CryptoJS.HmacSHA256(string, secret)); } ``` ### Notes - To get the latest addon, please delete `~/Library/Application Support/com.proxyman.NSProxy/addons/CryptoJS.js` and relaunch the Beta build (This will be automatically done if I bump a new version in the next release, but for now, please do it manually 😄 )
Author
Owner

@nilayp commented on GitHub (Feb 20, 2021):

Unfortunately, your implementation didn't work because you returned a String.

The algorithm (implemented in node.js) used by AWS for signing keys is here (See code sample called "getSignatureKey"): https://docs.aws.amazon.com/general/latest/gr/signature-v4-examples.html#signature-v4-examples-javascript

My reimplementation of this in Proxyman scripting is below. Notice that this algorithm requires the byte array for each operation and then returns a byte array to the caller, which is also expecting a byte array. My converting each operation's output to a String, the computed signature is incorrect.

function getSignatureKey(key, dateStamp, regionName, serviceName) {
    var kDate = HmacSHA256(dateStamp, 'AWS4' + key);
    var kRegion = HmacSHA256(regionName, kDate);
    var kService = HmacSHA256(serviceName, kRegion);
    var kSigning = HmacSHA256('aws4_request', kService);
    return kSigning;
}

Once again, thanks for the quick effort. :)

<!-- gh-comment-id:782706479 --> @nilayp commented on GitHub (Feb 20, 2021): Unfortunately, your implementation didn't work because you returned a String. The algorithm (implemented in node.js) used by AWS for signing keys is here (See code sample called "getSignatureKey"): https://docs.aws.amazon.com/general/latest/gr/signature-v4-examples.html#signature-v4-examples-javascript My reimplementation of this in Proxyman scripting is below. Notice that this algorithm requires the byte array for each operation and then returns a byte array to the caller, which is also expecting a byte array. My converting each operation's output to a String, the computed signature is incorrect. ``` function getSignatureKey(key, dateStamp, regionName, serviceName) { var kDate = HmacSHA256(dateStamp, 'AWS4' + key); var kRegion = HmacSHA256(regionName, kDate); var kService = HmacSHA256(serviceName, kRegion); var kSigning = HmacSHA256('aws4_request', kService); return kSigning; } ``` Once again, thanks for the quick effort. :)
Author
Owner

@NghiaTranUIT commented on GitHub (Feb 21, 2021):

Ah, I understand. I will use your version 👍

<!-- gh-comment-id:782781756 --> @NghiaTranUIT commented on GitHub (Feb 21, 2021): Ah, I understand. I will use your version 👍
Author
Owner

@NghiaTranUIT commented on GitHub (Feb 21, 2021):

The final beta here: https://proxyman.s3.us-east-2.amazonaws.com/beta/Proxyman_2.18.0_HmacSHA256_v2.dmg

Thank you for your contribution 🎉

<!-- gh-comment-id:782784546 --> @NghiaTranUIT commented on GitHub (Feb 21, 2021): The final beta here: https://proxyman.s3.us-east-2.amazonaws.com/beta/Proxyman_2.18.0_HmacSHA256_v2.dmg Thank you for your contribution 🎉
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/Proxyman#790
No description provided.