Description
Verifies the signature of the data using asymmetric algorithm.
Applies to
CrypterObject objects
Syntax
crypter.AsymmetricVerifySign (AsymmetricAlgorithm algorithm, blob variable, blob pubkey, blob sign)
crypter.AsymmetricVerifySign (AsymmetricAlgorithm algorithm, SHAAlgorithm hashtype, blob variable, blob pubkey, blob sign)
crypter.AsymmetricVerifySign (AsymmetricAlgorithm algorithm, SignatureStandard standard, SHAAlgorithm hashtype, blob variable, blob pubkey, blob sign)
|
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 verify 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. |
|
pubKey |
A blob specifying the public key. When standard is PSS and hashType is SHA512 or SHA3_512, the pubKey length must be greater than or equal to 2048. |
|
sign |
A blob specifying the signature. |
Return value
Integer. Returns 1 if it succeeds and -1 if it failed. If any argument's value is null, the method returns null. If an error occurs, throw the exception.
Usage
The asymmetric encryption and signature verification functions in
the CrypterObject are based on Crypto++, and their key format differs from
common standards (e.g., OpenSSL, .NET). As a result, functions such as
AsymmetricVerifySign cannot be used for validating tokens or
digital signatures generated outside PowerBuilder.
If you require token validation or cross-platform interoperability, we recommend either:
-
Performing the validation on the authorization server, or
-
Using PowerBuilder's Call .NET Assembly feature to execute .NET cryptographic code
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
Integer li_isPass
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 data with RSA
lblb_signature = lnv_CrypterObject.AsymmetricSign(RSA!, lblb_data, lblb_privKey)
// Verify the RSA signature
li_isPass = lnv_CrypterObject.AsymmetricVerifySign(RSA!, lblb_data, lblb_pubKey, lblb_signature)
if li_isPass = 1 then
messagebox("Success", "Verification succeeded!")
else
messagebox("Error", "Verification failed!")
end if
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)
// Validate 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


