Crypto Question

I need to encrypt with hmac-SHA256 a string that contains ‘\n’ in it.

I’ve tested the output of the crypto.hmac(crypto.sha256) method against an online calculator and as long as the string DOES NOT include ‘\n’ they match up. But as soon as I add that “new line” code, the returned encrypted strings don’t match.
below is an example:

text to encode: \n
key to encode: key

CoronaSDK result:
2e2023d953f100d6d6a5ee33810c9e47057ef9ecd698c719377ec1fe43af038b
Online Calculator result:
8a796b8d7f9d0bd2e7620975116f523ab0aa48e1e6f8fb0e09c7f45a01736674

testing WITHOUT the \n text:

text to encode: test
key to encode: key

02afb56304902c656fcb737cdd03de6205bb6d401da2812efd9b2d36a08af159

02afb56304902c656fcb737cdd03de6205bb6d401da2812efd9b2d36a08af159

THEY MATCH!

Any Ideas? [import]uid: 64596 topic_id: 22457 reply_id: 322457[/import]

have you tried the character 13 than the \n ?? [import]uid: 3826 topic_id: 22457 reply_id: 89572[/import]

Thank you very much for the response.

I’m not familiar with the “character 13” you’ve suggested. If you could indulge me with just a little more info I would both greatly appreciate it and attempt it.

I have tried replacing the “” symbol with “%5C” which I understand to be the url encoded form of “”. [import]uid: 64596 topic_id: 22457 reply_id: 89574[/import]

Instead of using double quotes for your string, try the [[…]] notation.

print (crypto.hmac( crypto.sha256, [[\n]], “key” ) )
– 8a796b8d7f9d0bd2e7620975116f523ab0aa48e1e6f8fb0e09c7f45a01736674 [import]uid: 44647 topic_id: 22457 reply_id: 89576[/import]