Description
Sign data to produce a signature using asymmetric algorithm.
Applies to
CrypterObject objects
Syntax
crypter.AsymmetricSign (AsymmetricAlgorithm algorithm, blob variable, blob privkey)
crypter.AsymmetricSign (AsymmetricAlgorithm algorithm, SHAAlgorithm hashtype, blob variable, blob privkey)
crypter.AsymmetricSign (AsymmetricAlgorithm algorithm, SignatureStandard standard, SHAAlgorithm hashtype, blob variable, blob privkey)
|
Argument |
Description |
|---|---|
|
crypter |
The name of the CrypterObject object |
|
algorithm |
A value of the AsymmetricAlgorithm enumerated type that specifies the type of asymmetric algorithm. Values are:
|
|
standard |
A value of the SignatureStandard enumerated type that specifies the signature standard type. Standard only takes effect when algorithm is RSA or Rabin. If not set, PKCS1V15 is used by default. Values are:
|
|
hashType |
A value of the SHAAlgorithm enumerated type that specifies the type of hash algorithm. Values are:
|
|
variable |
A blob whose value is the data you want to sign with Public-Key cipher. When using the system blob function to convert a string to a blob, it is recommended to specify its encoding argument to be EncodingANSI! (for English characters only) or EncodingUTF8!, otherwise, the default EncodingUTF16LE! will be used. |
|
privKey |
A blob specifying the private key. When standard is PSS and hashType is SHA512 or SHA3_512, the privkey length must be greater than or equal to 2048. |
Return value
Blob. Returns the signature of the data if it succeeds. If any argument's value is null, the method returns null. If an error occurs, throw the exception.
Examples
The following code example demonstrates how to sign data using RSA with a private key, and then verifies the signature using the corresponding RSA public key.
Blob lblb_data
Blob lblb_privKey
Blob lblb_pubKey
Blob lblb_signature
lblb_data = Blob("Test Rsa", EncodingANSI!)
CrypterObject lnv_CrypterObject
lnv_CrypterObject = Create CrypterObject
// Generate the private key
lnv_CrypterObject.AsymmetricGenerateKey(RSA!, 1024, lblb_privKey, lblb_pubKey)
// Sign with RSA
lblb_signature = lnv_CrypterObject.AsymmetricSign(RSA!, lblb_data, lblb_privKey)
The following code example signs data using RSA and SHA1 and then verifies the signature using the same algorithm.
Blob lblb_data
Blob lblb_privKey
Blob lblb_pubKey
Integer li_isPass
Blob lblb_signature
CoderObject lco_Code
lco_Code = create CoderObject
lblb_data = Blob("Test Rsa", EncodingANSI!)
CrypterObject lnv_CrypterObject
lnv_CrypterObject = Create CrypterObject
// Generate the private key
lnv_CrypterObject.AsymmetricGenerateKey(RSA!, 1024, lblb_privKey, lblb_pubKey)
// Sign with RSA and SHA1
lblb_signature = lnv_CrypterObject.AsymmetricSign(RSA!, SHA1!, lblb_data, lblb_privKey)
// Verify with RSA and SHA1
li_isPass = lnv_CrypterObject.AsymmetricVerifySign(RSA!, SHA1!, lblb_data, lblb_pubKey, lblb_signature)
messagebox( "AsymmetricVerifySign return value", li_isPass)
destroy lnv_CrypterObject
destroy lco_Code
The following code example signs data using RSA, PSS, and SHA3_512 and then verifies the signature with using the same algorithm.
Blob lblb_data
Blob lblb_privKey
Blob lblb_pubKey
String ls_HexStr
Blob lblb_signature
Integer li_isPass
CoderObject lco_Code
lco_Code = create CoderObject
CrypterObject lnv_CrypterObject
lnv_CrypterObject = Create CrypterObject
lblb_data = Blob("Test Rsa", EncodingANSI!)
// Generate the private key. SHA512 and SHA3_512 key lengths must be greater than 1024
lnv_CrypterObject.AsymmetricGenerateKey(RSA!, 2048, lblb_privKey, lblb_pubKey)
// Sign with RSA, PSS, and SHA3_512
lblb_signature = lnv_CrypterObject.AsymmetricSign(RSA!,PSS!, SHA3_512!, lblb_data, lblb_privKey)
// Verify with RSA, PSS, and SHA3_512
li_isPass = lnv_CrypterObject.AsymmetricVerifySign(RSA!,PSS!, SHA3_512!, lblb_data, lblb_pubKey, lblb_signature)
messagebox( "AsymmetricVerifySign return value", li_isPass)
destroy lnv_CrypterObject
destroy lco_Code
See also


