HMAC (hash-based message authentication code, aka data signing) in Mathematica -


It seems that there is an implementation of HMAC in every language below (see below.) And the algorithm is quite straightforward: / P>

Has anyone applied it to mathematica?

  • There are signs of implementation in other languages:
  • P>

    This is my implementation:

    The first few utility functions:

      (* The length is left * n * with the pad string SX). Stripaders [s_ , N_, x_]: = stringgeon @ padrite [character], n, x] stripad [s_, n_, x_]: = string jan @ pad left [character] [n], n, x] (* hex representation; Optionally pad length from n with pins) hex [x_, n_: null]: = if [n === faucet, identification, stripad [, x, 16] (* coordinate all the arguments as strings ( X) if they are not already). *) Cat = StringJoin @@ (ToString / @ {##}) & amp;; (* Takes a string like "Xy" and gives hex representation of the bytes (ASCI code) (a string even twice a long). *) Tobias [s_]: = cat @@ (hex [#, 2 ] & Amp;; / ToCharacterCode [s]) (* takes a length string like "0a10" and gives a length n / 2 string where in this example the first letter is in ascii code 10 ("a" hex ) And second, whatever the Ascii code is 16 ("10" in hex). *) Goodbye [HS_]: = Sectorcode [unhex / @ cat @@@ partition [character [hs], 2]] (* given A bit integer bit Axray hexibixor [a_String, b_String]: = hex @ bitxor [unhex @ a, unhex @ b] (* string s, repeat n times.) Strrpt [s_, n_]: = cat @@ ConstantArray [ S, n] (* Byte length length of half length string by hex string. *) Bytelen [s_]: = roof [string length [s] / 2]  

    Implement the original hash Methamatica The question is not quite trivial in this question.

      (* The only way for Hamish is to give a date in the form of a string in Mama A.) Hash [s_String, h _: "SHA"]: = Module [{stream = Stringtostrym [S] results} result = Failhash [stream, H]; Off [stream]; Hex @ result]; Finally, there is the HMAC function:  
     Return to the HMAC digest using the hash function H for string with the  (* key code. Hmac [s_, k_, h_: sha1]: = Module [{b, key, ipad, opad}, b = 64 ; (* Block size for both MD5 and RA 2) Key = Tobeit [Key]; Key = if [ByTellon [Key]> B, H [Bybytes @ key], Key]; Key = Stripad [Key , 2b, "0"]; Ipad = hexbitxor [strrpt ["36", b], key]; Opad = hexbitxor [strrpt ["5c", b], key]; F [sbites] [OPD  

    I have confirmed that this is all examples For example:

      HMAC ["Do not Want to Do Anything?", "Jeff", MD5]  

    Return

      "750c783e6ab0b503eaa86e310a5db738"  

    Comments

    Popular posts from this blog

    c# - How to capture HTTP packet with SharpPcap -

    jquery - SimpleModal Confirm fails to submit form -

    php - Multiple Select with Explode: only returns the word "Array" -