Class Index | File Index

Classes


Class KJUR.crypto.MessageDigest

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

Class Summary
Constructor Attributes Constructor Name and Description
 
MessageDigest class which is very similar to java.security.MessageDigest class

Currently this supports following algorithm and providers combination:
  • md5 - cryptojs
  • sha1 - cryptojs
  • sha224 - cryptojs
  • sha256 - cryptojs
  • sha384 - cryptojs
  • sha512 - cryptojs
  • ripemd160 - cryptojs
  • sha256 - sjcl (NEW from crypto.js 1.0.4)
Field Summary
Field Attributes Field Name and Description
 
static Array of resulted byte length of hash (ex.
Method Summary
Method Attributes Method Name and Description
 
completes hash calculation and returns hash result
 
digestHex(hex)
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
<static>  
KJUR.crypto.MessageDigest.getCanonicalAlgName(alg)
get canonical hash algorithm name
This static method normalizes from any hash algorithm name such as "SHA-1", "SHA1", "MD5", "sha512" to lower case name without hyphens such as "sha1".
<static>  
KJUR.crypto.MessageDigest.getHashLength(alg)
get resulted hash byte length for specified algorithm name
This static method returns resulted byte length for specified algorithm name such as "SHA-1".
 
setAlgAndProvider(alg, prov)
set hash algorithm and provider
This methods set an algorithm and a cryptographic provider.
 
updateHex(hex)
update digest by specified hexadecimal string
 
update digest by specified string
Class Detail
KJUR.crypto.MessageDigest(params)
MessageDigest class which is very similar to java.security.MessageDigest class

Currently this supports following algorithm and providers combination:
  • md5 - cryptojs
  • sha1 - cryptojs
  • sha224 - cryptojs
  • sha256 - cryptojs
  • sha384 - cryptojs
  • sha512 - cryptojs
  • ripemd160 - cryptojs
  • sha256 - sjcl (NEW from crypto.js 1.0.4)
// CryptoJS provider sample
var md = new KJUR.crypto.MessageDigest({alg: "sha1", prov: "cryptojs"});
md.updateString('aaa')
var mdHex = md.digest()

// SJCL(Stanford JavaScript Crypto Library) provider sample
var md = new KJUR.crypto.MessageDigest({alg: "sha256", prov: "sjcl"}); // sjcl supports sha256 only
md.updateString('aaa')
var mdHex = md.digest()

// HASHLENGTH property
KJUR.crypto.MessageDigest.HASHLENGTH['sha1'] &rarr 20
KJUR.crypto.MessageDigest.HASHLENGTH['sha512'] &rarr 64
Parameters:
{Array} params
parameters for constructor
Field Detail
{Array} HASHLENGTH
static Array of resulted byte length of hash (ex. HASHLENGTH["sha1"] == 20)
Method Detail
digest()
completes hash calculation and returns hash result
md.digest()

digestHex(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

digestString(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> {String} KJUR.crypto.MessageDigest.getCanonicalAlgName(alg)
get canonical hash algorithm name
This static method normalizes from any hash algorithm name such as "SHA-1", "SHA1", "MD5", "sha512" to lower case name without hyphens such as "sha1".
KJUR.crypto.MessageDigest.getCanonicalAlgName("SHA-1") &rarr "sha1"
KJUR.crypto.MessageDigest.getCanonicalAlgName("MD5")   &rarr "md5"
Parameters:
{String} alg
hash algorithm name (ex. MD5, SHA-1, SHA1, SHA512 et.al.)
Since:
jsrsasign 6.2.0 crypto 1.1.10
Returns:
{String} canonical hash algorithm name

<static> {Integer} KJUR.crypto.MessageDigest.getHashLength(alg)
get resulted hash byte length for specified algorithm name
This static method returns resulted byte length for specified algorithm name such as "SHA-1".
KJUR.crypto.MessageDigest.getHashLength("SHA-1") &rarr 20
KJUR.crypto.MessageDigest.getHashLength("sha1") &rarr 20
Parameters:
{String} alg
non-canonicalized hash algorithm name (ex. MD5, SHA-1, SHA1, SHA512 et.al.)
Since:
jsrsasign 6.2.0 crypto 1.1.10
Returns:
{Integer} resulted hash byte length

setAlgAndProvider(alg, prov)
set hash algorithm and provider
This methods set an algorithm and a cryptographic provider.
Here is acceptable algorithm names ignoring cases and hyphens: NOTE: Since jsrsasign 6.2.0 crypto 1.1.10, this method ignores upper or lower cases. Also any hyphens (i.e. "-") will be ignored so that "SHA1" or "SHA-1" will be acceptable.
// for SHA1
md.setAlgAndProvider('sha1', 'cryptojs');
md.setAlgAndProvider('SHA1');
// for RIPEMD160
md.setAlgAndProvider('ripemd160', 'cryptojs');
Parameters:
{String} alg
hash algorithm name
{String} prov
provider name

updateHex(hex)
update digest by specified hexadecimal string
md.updateHex('0afe36');
Parameters:
{String} hex
hexadecimal string to update

updateString(str)
update digest by specified string
md.updateString('New York');
Parameters:
{String} str
string to update

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