Class Index | File Index

Classes


Class KJUR.crypto.Mac

Mac class which is very similar to java.security.Mac class
Defined in: crypto-1.1.js.

Class Summary
Constructor Attributes Constructor Name and Description
 
KJUR.crypto.Mac(params)
Mac(Message Authentication Code) class which is very similar to java.security.Mac class
Currently this supports following algorithm and providers combination:
  • hmacmd5 - cryptojs
  • hmacsha1 - cryptojs
  • hmacsha224 - cryptojs
  • hmacsha256 - cryptojs
  • hmacsha384 - cryptojs
  • hmacsha512 - cryptojs
NOTE: HmacSHA224 and HmacSHA384 issue was fixed since jsrsasign 4.1.4.
Method Summary
Method Attributes Method Name and Description
 
completes hash calculation and returns hash result
 
performs final update on the digest using hexadecimal string, then completes the digest computation
 
performs final update on the digest using string, then completes the digest computation
 
set password for Mac
This method will set password for (H)Mac internally.
 
updateHex(hex)
update digest by specified hexadecimal string
 
update digest by specified string
Class Detail
KJUR.crypto.Mac(params)
Mac(Message Authentication Code) class which is very similar to java.security.Mac class
Currently this supports following algorithm and providers combination:
  • hmacmd5 - cryptojs
  • hmacsha1 - cryptojs
  • hmacsha224 - cryptojs
  • hmacsha256 - cryptojs
  • hmacsha384 - cryptojs
  • hmacsha512 - cryptojs
NOTE: HmacSHA224 and HmacSHA384 issue was fixed since jsrsasign 4.1.4. Please use 'ext/cryptojs-312-core-fix*.js' instead of 'core.js' of original CryptoJS to avoid those issue.
NOTE2: Hmac signature bug was fixed in jsrsasign 4.9.0 by providing CryptoJS bug workaround.
Please see KJUR.crypto.Mac.setPassword, how to provide password in various ways in detail.
var mac = new KJUR.crypto.Mac({alg: "HmacSHA256", "pass": "pass"});
mac.updateString('aaa')
mac.doFinal() → "5737da..."

// other password representation 
var mac = new KJUR.crypto.Mac({alg: "HmacSHA256", "pass": {"hex":  "6161"}});
var mac = new KJUR.crypto.Mac({alg: "HmacSHA256", "pass": {"utf8": "aa"}});
var mac = new KJUR.crypto.Mac({alg: "HmacSHA256", "pass": {"rstr": "\x61\x61"}});
var mac = new KJUR.crypto.Mac({alg: "HmacSHA256", "pass": {"b64":  "Mi02/+...a=="}});
var mac = new KJUR.crypto.Mac({alg: "HmacSHA256", "pass": {"b64u": "Mi02_-...a"}});
Parameters:
{Array} params
parameters for constructor
Method Detail
doFinal()
completes hash calculation and returns hash result
var mac = new KJUR.crypto.Mac({alg: "HmacSHA256", "pass": "pass"});
mac.updateString('aaa')
mac.doFinal() → "5737da..."
Returns:
hexadecimal string of Mac result value

doFinalHex(hex)
performs final update on the digest using hexadecimal string, then completes the digest computation
var mac = new KJUR.crypto.Mac({alg: "HmacSHA256", "pass": "pass"});
mac.doFinalHex("616161") → "5737da..."
Parameters:
{String} hex
hexadecimal string to final update
Returns:
hexadecimal string of Mac result value

doFinalString(str)
performs final update on the digest using string, then completes the digest computation
var mac = new KJUR.crypto.Mac({alg: "HmacSHA256", "pass": "pass"});
mac.doFinalString("aaa") → "5737da..."
Parameters:
{String} str
raw string to final update
Returns:
hexadecimal string of Mac result value

setPassword(pass)
set password for Mac
This method will set password for (H)Mac internally. Argument 'pass' can be specified as following: It is *STRONGLY RECOMMENDED* that explicit representation of password argument to avoid ambiguity. For example string "6161" can mean a string "6161" or a hexadecimal string of "aa" (i.e. \x61\x61).
mac = KJUR.crypto.Mac({'alg': 'hmacsha256'});
// set password by implicit raw string
mac.setPassword("\x65\x70\xb9\x0b");
mac.setPassword("password");
// set password by implicit hexadecimal string
mac.setPassword("6570b90b");
mac.setPassword("6570B90B");
// set password by explicit raw string
mac.setPassword({"rstr": "\x65\x70\xb9\x0b"});
// set password by explicit hexadecimal string
mac.setPassword({"hex": "6570b90b"});
// set password by explicit utf8 string
mac.setPassword({"utf8": "passwordパスワード");
// set password by explicit Base64 string
mac.setPassword({"b64": "Mb+c3f/=="});
// set password by explicit Base64URL string
mac.setPassword({"b64u": "Mb-c3f_"});
Parameters:
{Object} pass
password for Mac
Since:
crypto 1.1.7 jsrsasign 4.9.0

updateHex(hex)
update digest by specified hexadecimal string
var mac = new KJUR.crypto.Mac({alg: "HmacSHA256", "pass": "pass"});
mac.updateHex('616161')
mac.doFinal() → "5737da..."
Parameters:
{String} hex
hexadecimal string to update

updateString(str)
update digest by specified string
var mac = new KJUR.crypto.Mac({alg: "HmacSHA256", "pass": "pass"});
mac.updateString('aaa')
mac.doFinal() → "5737da..."
Parameters:
{String} str
string to update

© 2012-2023 Kenji Urushima, All rights reserved
Documentation generated by JsDoc Toolkit 2.4.0