On Mon, Feb 6, 2012 at 11:21 PM, John Refior <jref...@gmail.com> wrote:
> I am trying to create a CMAC out of some JSON data (I have a reason for > doing this -- part of the authorization allowing my REST client to > communicate with a server that requires it). I figured I would use > Digest::CMAC to do this (but if someone knows a better way, please let me > know). However, I'm trying to create the CMAC out of JSON data, and I'm > getting an error. I wrote a little test script to demonstrate, here's the > code: .... > I added the Crypt::Rijndael->encrypt at the end just to see if that would work on the bare JSON string, and it does. Here's the output of the script: > > <OUTPUT> > $json is: {"three":3,"five":5,"one":1,"two":2,"four":4} > Attempting to Digest::CMAC->add($json) > [eval error]: encrypt: datasize not multiple of blocksize (16 bytes) at > /export/home/apps/public/lib/perl5/site_perl/5.10.0/Digest/OMAC/Base.pm > line 56. > > -------------------------------------------------------------------------------- > Crypt::Rijndael->encrypt(\$json): G`'/Mβ©Y¦¾Ï)=ôÎlÛÝf?´²lÕeyûÊ¡í > </OUTPUT> > > If not for the eval, the script would stop execution at that error. > The Crypt::Rijndael->encrypt call on the bare JSON does not cause an error. > > Does anyone have a suggestion for how I can create a CMAC using a JSON > string? > Thought I would write again to say that it appears I've fixed this problem by switching from JSON::to_json to encode_json. I haven't yet figured out why this makes a difference (encoding issue? feel free to chime in if you have an idea), but it appears it does. Thanks, John