Class Index | File Index

Classes


Class KJUR.crypto.Signature

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

Class Summary
Constructor Attributes Constructor Name and Description
 
Signature class which is very similar to java.security.Signature class
As for params of constructor's argument, it can be specify following attributes:
  • alg - signature algorithm name (ex.
Field Summary
Field Attributes Field Name and Description
 
Current state of this signature object whether 'SIGN', 'VERIFY' or null
Method Summary
Method Attributes Method Name and Description
 
init(key, pass)
Initialize this object for signing or verifying depends on key This method is very useful initialize method for Signature class since you just specify key then this method will automatically initialize it using KEYUTIL.getKey method.
 
setAlgAndProvider(alg, prov)
set signature algorithm and provider
 
sign()
Returns the signature bytes of all data updates as a hexadecimal string
 
signHex(hex)
performs final update on the sign using hexadecimal string, then returns the signature bytes of all data updates as a hexadecimal string
 
performs final update on the sign using string, then returns the signature bytes of all data updates as a hexadecimal string
 
updateHex(hex)
Updates the data to be signed or verified by a hexadecimal string
 
Updates the data to be signed or verified by a string
 
verify(str)
verifies the passed-in signature.
Class Detail
KJUR.crypto.Signature(params)
Signature class which is very similar to java.security.Signature class
As for params of constructor's argument, it can be specify following attributes:
  • alg - signature algorithm name (ex. {MD5,SHA1,SHA224,SHA256,SHA384,SHA512,RIPEMD160}with{RSA,ECDSA,DSA})
  • provider - currently 'cryptojs/jsrsa' only

SUPPORTED ALGORITHMS AND PROVIDERS

This Signature class supports following signature algorithm and provider names:
  • MD5withRSA - cryptojs/jsrsa
  • SHA1withRSA - cryptojs/jsrsa
  • SHA224withRSA - cryptojs/jsrsa
  • SHA256withRSA - cryptojs/jsrsa
  • SHA384withRSA - cryptojs/jsrsa
  • SHA512withRSA - cryptojs/jsrsa
  • RIPEMD160withRSA - cryptojs/jsrsa
  • MD5withECDSA - cryptojs/jsrsa
  • SHA1withECDSA - cryptojs/jsrsa
  • SHA224withECDSA - cryptojs/jsrsa
  • SHA256withECDSA - cryptojs/jsrsa
  • SHA384withECDSA - cryptojs/jsrsa
  • SHA512withECDSA - cryptojs/jsrsa
  • RIPEMD160withECDSA - cryptojs/jsrsa
  • MD5withRSAandMGF1 - cryptojs/jsrsa
  • SHAwithRSAandMGF1 - cryptojs/jsrsa
  • SHA1withRSAandMGF1 - cryptojs/jsrsa
  • SHA224withRSAandMGF1 - cryptojs/jsrsa
  • SHA256withRSAandMGF1 - cryptojs/jsrsa
  • SHA384withRSAandMGF1 - cryptojs/jsrsa
  • SHA512withRSAandMGF1 - cryptojs/jsrsa
  • RIPEMD160withRSAandMGF1 - cryptojs/jsrsa
  • SHA1withDSA - cryptojs/jsrsa
  • SHA224withDSA - cryptojs/jsrsa
  • SHA256withDSA - cryptojs/jsrsa
As for RSA-PSS signature algorithm names and signing parameters such as MGF function and salt length, please see KJUR.asn1.x509.AlgorithmIdentifier class. Here are supported elliptic cryptographic curve names and their aliases for ECDSA:
  • secp256k1
  • secp256r1, NIST P-256, P-256, prime256v1
  • secp384r1, NIST P-384, P-384
  • secp521r1, NIST P-521, P-521
NOTE1: DSA signing algorithm is also supported since crypto 1.1.5.

EXAMPLES

// RSA signature generation
var sig = new KJUR.crypto.Signature({"alg": "SHA1withRSA"});
sig.init(prvKeyPEM);
sig.updateString('aaa');
var hSigVal = sig.sign();

// DSA signature validation
var sig2 = new KJUR.crypto.Signature({"alg": "SHA1withDSA"});
sig2.init(certPEM);
sig.updateString('aaa');
var isValid = sig2.verify(hSigVal);

// ECDSA signing
var sig = new KJUR.crypto.Signature({'alg':'SHA1withECDSA'});
sig.init(prvKeyPEM);
sig.updateString('aaa');
var sigValueHex = sig.sign();

// ECDSA verifying
var sig2 = new KJUR.crypto.Signature({'alg':'SHA1withECDSA'});
sig.init(certPEM);
sig.updateString('aaa');
var isValid = sig.verify(sigValueHex);
Parameters:
{Array} params
parameters for constructor
Field Detail
{String} state
Current state of this signature object whether 'SIGN', 'VERIFY' or null
Method Detail
init(key, pass)
Initialize this object for signing or verifying depends on key This method is very useful initialize method for Signature class since you just specify key then this method will automatically initialize it using KEYUTIL.getKey method. As for 'key', following argument type are supported:
signing
verification
sig.init(sCertPEM)
Parameters:
{Object} key
specifying public or private key as plain/encrypted PKCS#5/8 PEM file, certificate PEM or RSAKey, KJUR.crypto.DSA or KJUR.crypto.ECDSA object
{String} pass
(OPTION) passcode for encrypted private key
Since:
crypto 1.1.3

setAlgAndProvider(alg, prov)
set signature algorithm and provider
md.setAlgAndProvider('SHA1withRSA', 'cryptojs/jsrsa');
Parameters:
{String} alg
signature algorithm name
{String} prov
provider name

sign()
Returns the signature bytes of all data updates as a hexadecimal string
var hSigValue = sig.sign()
Returns:
the signature bytes as a hexadecimal string

signHex(hex)
performs final update on the sign using hexadecimal string, then returns the signature bytes of all data updates as a hexadecimal string
var hSigValue = sig.signHex('1fdc33')
Parameters:
{String} hex
hexadecimal string to final update
Returns:
the signature bytes of a hexadecimal string

signString(str)
performs final update on the sign using string, then returns the signature bytes of all data updates as a hexadecimal string
var hSigValue = sig.signString('aaa')
Parameters:
{String} str
string to final update
Returns:
the signature bytes of a hexadecimal string

updateHex(hex)
Updates the data to be signed or verified by a hexadecimal string
sig.updateHex('1f2f3f')
Parameters:
{String} hex
hexadecimal string to use for the update

updateString(str)
Updates the data to be signed or verified by a string
sig.updateString('aaa')
Parameters:
{String} str
string to use for the update

{Boolean} verify(str)
verifies the passed-in signature.
var isValid = sig.verify('1fbcefdca4823a7(snip)')
Parameters:
{String} str
string to final update
Returns:
{Boolean} true if the signature was verified, otherwise false

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