Roku Developer Program

Join our online forum to talk to Roku developers and fellow channel creators. Ask questions, share tips with the community, and find helpful resources.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
DavidAW
Visitor

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 *)hmacSHA256WithKey:(NSData *)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 2
RokuKC
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
Visitor

Re: Help with SHA-256 (roEVPDigest)

Perfect, thanks! Now iOS and Roku are in sync on the HMAC output.
0 Kudos
Need Assistance?
Welcome to the Roku Community! Feel free to search our Community for answers or post your question to get help.

Become a Roku Streaming Expert!

Share your expertise, help fellow streamers, and unlock exclusive rewards as part of the Roku Community. Learn more.