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
<static>  
KJUR.crypto.Signature.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.
<static>  
KJUR.crypto.Signature.initSign(param)
Initialize this object for signing Private key information will be provided as 'param' parameter and the value will be following:
  • RSAKey object for RSA signing
  • associative array for ECDSA signing (ex.
<static>  
KJUR.crypto.Signature.initVerifyByCertificatePEM(certPEM)
Initialize this object for verifying with a certficate
<static>  
KJUR.crypto.Signature.initVerifyByPublicKey(param)
Initialize this object for verifying with a public key Public key information will be provided as 'param' parameter and the value will be following:
  • RSAKey object for RSA verification
  • associative array for ECDSA verification (ex.
<static>  
KJUR.crypto.Signature.setAlgAndProvider(alg, prov)
set signature algorithm and provider
<static>  
KJUR.crypto.Signature.sign()
Returns the signature bytes of all data updates as a hexadecimal string
<static>  
KJUR.crypto.Signature.signHex(hex)
performs final update on the sign using hexadecimal string, then returns the signature bytes of all data updates as a hexadecimal string
<static>  
KJUR.crypto.Signature.signString(str)
performs final update on the sign using string, then returns the signature bytes of all data updates as a hexadecimal string
<static>  
KJUR.crypto.Signature.updateHex(hex)
Updates the data to be signed or verified by a hexadecimal string
<static>  
KJUR.crypto.Signature.updateString(str)
Updates the data to be signed or verified by a string
<static>  
KJUR.crypto.Signature.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
  • 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
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
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
<static> KJUR.crypto.Signature.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

<static> KJUR.crypto.Signature.initSign(param)
Initialize this object for signing Private key information will be provided as 'param' parameter and the value will be following:
sig.initSign(prvKey)
Parameters:
{Object} param
RSAKey object of public key or associative array for ECDSA
Deprecated:
from crypto 1.1.5. please use init() method instead.

<static> KJUR.crypto.Signature.initVerifyByCertificatePEM(certPEM)
Initialize this object for verifying with a certficate
sig.initVerifyByCertificatePEM(certPEM)
Parameters:
{String} certPEM
PEM formatted string of certificate
Deprecated:
from crypto 1.1.5. please use init() method instead.
Since:
1.0.2

<static> KJUR.crypto.Signature.initVerifyByPublicKey(param)
Initialize this object for verifying with a public key Public key information will be provided as 'param' parameter and the value will be following:
sig.initVerifyByPublicKey(rsaPrvKey)
Parameters:
{Object} param
RSAKey object of public key or associative array for ECDSA
Deprecated:
from crypto 1.1.5. please use init() method instead.
Since:
1.0.2

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

<static> KJUR.crypto.Signature.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

<static> KJUR.crypto.Signature.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

<static> KJUR.crypto.Signature.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

<static> KJUR.crypto.Signature.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

<static> KJUR.crypto.Signature.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

<static> {Boolean} KJUR.crypto.Signature.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 Kenji Urushima, All rights reserved
Documentation generated by JsDoc Toolkit 2.4.0