Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support passing byte_array into crypto functions #1368

Merged
merged 1 commit into from
Oct 12, 2023

Conversation

Pieter12345
Copy link
Contributor

@Pieter12345 Pieter12345 commented Sep 29, 2023

This adds a way to perform the existing crypto functions using both byte_array keys and values. I needed this for signing a HTTP request to access an AWS S3 bucket, which works with this modification.

Note that I also needed the following code to convert the returned hex string to a byte array:

proc _hex_to_ba(string @hex) {
	byte_array @ret = byte_array();
	for(int @i = 0, @i < length(@hex), @i += 2) {
		int @val = parse_int(substr(@hex, @i, @i + 2), 16);
		ba_put_byte(@ret, if(@val < 128, @val, @val - 256));
	}
	return(@ret);
}

It could be helpful to add some hex_string_to_ba() function to provide this functionality out of the box, or add some option to make the hmac functions return a byte array instead of a hex string. If this is the case, issues should be created for those feature requests.

Affected functions: hmac_md5, hmac_sha1, hmac_sha256, md5, sha1, sha256 and sha512.
@Pieter12345 Pieter12345 changed the title Support passing byte_array into hmac functions Support passing byte_array into crypto functions Oct 12, 2023
@Pieter12345 Pieter12345 merged commit e705952 into EngineHub:master Oct 12, 2023
2 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant