Class KJUR.crypto.Mac
Mac class which is very similar to java.security.Mac class
Defined in: crypto-1.1.js.
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:
|
Method Attributes | Method Name and Description |
---|---|
<static> |
KJUR.crypto.Mac.doFinal()
completes hash calculation and returns hash result
|
<static> |
KJUR.crypto.Mac.doFinalHex(hex)
performs final update on the digest using hexadecimal string,
then completes the digest computation
|
<static> |
KJUR.crypto.Mac.doFinalString(str)
performs final update on the digest using string, then completes the digest computation
|
<static> |
KJUR.crypto.Mac.setPassword(pass)
set password for Mac
This method will set password for (H)Mac internally.
|
<static> |
KJUR.crypto.Mac.updateHex(hex)
update digest by specified hexadecimal string
|
<static> |
KJUR.crypto.Mac.updateString(str)
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:
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.
Currently this supports following algorithm and providers combination:
- hmacmd5 - cryptojs
- hmacsha1 - cryptojs
- hmacsha224 - cryptojs
- hmacsha256 - cryptojs
- hmacsha384 - cryptojs
- hmacsha512 - cryptojs
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: "HmacSHA1", "pass": "pass"}); mac.updateString('aaa') var macHex = md.doFinal() // 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
<static>
KJUR.crypto.Mac.doFinal()
completes hash calculation and returns hash result
md.digest()
<static>
KJUR.crypto.Mac.doFinalHex(hex)
performs final update on the digest using hexadecimal string,
then completes the digest computation
md.digestHex('0f2abd')
- Parameters:
- {String} hex
- hexadecimal string to final update
<static>
KJUR.crypto.Mac.doFinalString(str)
performs final update on the digest using string, then completes the digest computation
md.digestString('aaa')
- Parameters:
- {String} str
- string to final update
<static>
KJUR.crypto.Mac.setPassword(pass)
set password for Mac
This method will set password for (H)Mac internally.
Argument 'pass' can be specified as following:
- even length string of 0..9, a..f or A-F: implicitly specified as hexadecimal string
- not above string: implicitly specified as raw string
- {rstr: "\x65\x70"}: explicitly specified as raw string
- {hex: "6570"}: explicitly specified as hexacedimal string
- {utf8: "秘密"}: explicitly specified as UTF8 string
- {b64: "Mi78..=="}: explicitly specified as Base64 string
- {b64u: "Mi7-_"}: explicitly specified as Base64URL string
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
<static>
KJUR.crypto.Mac.updateHex(hex)
update digest by specified hexadecimal string
md.updateHex('0afe36');
- Parameters:
- {String} hex
- hexadecimal string to update
<static>
KJUR.crypto.Mac.updateString(str)
update digest by specified string
md.updateString('New York');
- Parameters:
- {String} str
- string to update