Class KJUR.crypto.Signature
Signature class which is very similar to java.security.Signature class
Defined in: crypto-1.1.js.
Constructor Attributes | Constructor Name and Description |
---|---|
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:
|
Field Attributes | Field Name and Description |
---|---|
Current state of this signature object whether 'SIGN', 'VERIFY' or null
|
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:
|
<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:
|
<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:
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
- secp256k1
- secp256r1, NIST P-256, P-256, prime256v1
- secp384r1, NIST P-384, P-384
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
- PEM formatted PKCS#8 encrypted RSA/ECDSA private key concluding "BEGIN ENCRYPTED PRIVATE KEY"
- PEM formatted PKCS#5 encrypted RSA/DSA private key concluding "BEGIN RSA/DSA PRIVATE KEY" and ",ENCRYPTED"
- PEM formatted PKCS#8 plain RSA/ECDSA private key concluding "BEGIN PRIVATE KEY"
- PEM formatted PKCS#5 plain RSA/DSA private key concluding "BEGIN RSA/DSA PRIVATE KEY" without ",ENCRYPTED"
- RSAKey object of private key
- KJUR.crypto.ECDSA object of private key
- KJUR.crypto.DSA object of private key
verification
- PEM formatted PKCS#8 RSA/EC/DSA public key concluding "BEGIN PUBLIC KEY"
- PEM formatted X.509 certificate with RSA/EC/DSA public key concluding "BEGIN CERTIFICATE", "BEGIN X509 CERTIFICATE" or "BEGIN TRUSTED CERTIFICATE".
- RSAKey object of public key
- KJUR.crypto.ECDSA object of public key
- KJUR.crypto.DSA object of public key
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:
- RSAKey object for RSA signing
- associative array for ECDSA signing
(ex.
{'ecprvhex': '1d3f..', 'eccurvename': 'secp256r1'}
)
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:
- RSAKey object for RSA verification
- associative array for ECDSA verification
(ex.
{'ecpubhex': '041f..', 'eccurvename': 'secp256r1'}
)
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