DataFlex
DataFlex
Verfies an RSA Signature
See more Apple Keychain Examples
Verifies an RSA signature against the original data.Chilkat DataFlex Downloads
Use ChilkatAx-win32.pkg
Procedure Test
Boolean iSuccess
Variant vBd
Handle hoBd
Integer i
Variant vBdSig
Handle hoBdSig
Variant vPubKey
Handle hoPubKey
Handle hoRsa
String sTemp1
Move False To iSuccess
// The following data was signed by the following example:
// RSA Sign using a Private Key on a USB Token or Smartcard
Get Create (RefClass(cComChilkatBinData)) To hoBd
If (Not(IsComObjectCreated(hoBd))) Begin
Send CreateComObject of hoBd
End
For i From 0 To 100
Get ComAppendEncoded Of hoBd "000102030405060708090A0B0C0D0E0F" "hex" To iSuccess
Loop
// Load the signature
Get Create (RefClass(cComChilkatBinData)) To hoBdSig
If (Not(IsComObjectCreated(hoBdSig))) Begin
Send CreateComObject of hoBdSig
End
Get ComLoadFile Of hoBdSig "rsaSignatures/test1.sig" To iSuccess
If (iSuccess = False) Begin
Showln "Failed to load the RSA signature"
Procedure_Return
End
// Get the public key to be used for signature verification.
Get Create (RefClass(cComChilkatPublicKey)) To hoPubKey
If (Not(IsComObjectCreated(hoPubKey))) Begin
Send CreateComObject of hoPubKey
End
Get ComLoadFromFile Of hoPubKey "rsaKeys/chilkat-rsa-2048.pem" To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoPubKey To sTemp1
Showln sTemp1
Procedure_Return
End
Get Create (RefClass(cComChilkatRsa)) To hoRsa
If (Not(IsComObjectCreated(hoRsa))) Begin
Send CreateComObject of hoRsa
End
Get pvComObject of hoPubKey to vPubKey
Get ComUsePublicKey Of hoRsa vPubKey To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoRsa To sTemp1
Showln sTemp1
Procedure_Return
End
// Verify the hash of the data against the signature.
// We pass in the original data. Internally, the hash is generated
// and used to validate the signature.
// Validating the RSA signature means two things:
// (1) the original data is exactly what was signed, and
// (2) it was signed by the owner of the RSA private key.
Get pvComObject of hoBd to vBd
Get pvComObject of hoBdSig to vBdSig
Get ComVerifyBd Of hoRsa vBd "sha256" vBdSig To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoRsa To sTemp1
Showln sTemp1
Showln "Signature invalid."
End
Else Begin
Showln "Signature valid."
End
End_Procedure