Roku Developer Program

Developers and content creators—a complete solution for growing an audience directly.
cancel
Showing results for 
Search instead for 
Did you mean: 
DavidAW
Level 7

Help with SHA-256 (roEVPDigest)

Hi all,
We have a mechanism for authenticating our REST APIs at my company based on an HMAC token. This token is generated using a pre-shared key and some hashing functions, specifically SHA-256. I initially implemented the hashing of a string as:

Function computeSHA256Hash(data as String) as String
ba = CreateObject("roByteArray")
ba.FromAsciiString(data)
digest = CreateObject("roEVPDigest")
digest.Setup("sha256")
return digest.Process(ba)
End Function


The problem is that the implementation on other platforms takes TWO parameters to the SHA function, the key and the data, but this seems to only take data. For comparison, here is the iOS function (in the Common Crypto library):

- (NSData *)hmacSHA256WithKeySmiley SadNSData *)key
{
unsigned char buffer[CC_SHA256_DIGEST_LENGTH] = {0};

CCHmac(kCCHmacAlgSHA256, [key bytes], [key length],
[self cStringUsingEncoding:NSUTF8StringEncoding], [self length], buffer);

return [NSData dataWithBytes:buffer length:CC_SHA256_DIGEST_LENGTH];
}


The specifics are not important, except that as you see it takes a key and data. Is there a way on the Roku to compute an HMAC with SHA-256 in this way?
0 Kudos
2 Replies
Roku Employee
Roku Employee

Re: Help with SHA-256 (roEVPDigest)

It sounds like you want look at roHMAC (https://sdkdocs.roku.com/display/sdkdoc/roHMAC).
0 Kudos
DavidAW
Level 7

Re: Help with SHA-256 (roEVPDigest)

Perfect, thanks! Now iOS and Roku are in sync on the HMAC output.
0 Kudos