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 |
---|---|
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
|
|
signString(str)
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
|
|
updateString(str)
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:
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
- secp256k1
- secp256r1, NIST P-256, P-256, prime256v1
- secp384r1, NIST P-384, P-384
- secp521r1, NIST P-521, P-521
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
- 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
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