DataFlex
DataFlex
Verify an RSA Signature Against the Signed Hash
See more Apple Keychain Examples
Demonstrates how to validate an RSA Signature against the hash that was signed.Chilkat DataFlex Downloads
Use ChilkatAx-win32.pkg
Procedure Test
Boolean iSuccess
Handle hoBd
Integer i
String sSha256_base64
String sBase64_rsa_sig
Variant vPubKey
Handle hoPubKey
Handle hoRsa
String sTemp1
Move False To iSuccess
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
Get ComGetHash Of hoBd "sha256" "base64" To sSha256_base64
Showln "sha256 hash in base64 format: " sSha256_base64
Move "AwF2BbOvL6jA5DwmMAc9n6J2Cc8PI6Rj5W079+aKJcIEtPWRzHor0Bvc3aftGM3Jbgj6SXlIC3M3RYS7UZOnfiHKFNZgbxaNT5WwsWooK42ZkC8DBZl0p7OunBUKd5SciUo+TKilioeUkriN3L1Zl9hwi3HVDVqgVo3XXskwIftSqLSFlepTLTmOWj9Y93dp8J4D9RyLtNgFQBc0WB22tyJTsuY56mLcWe1AMF3LizB9OrbwjynF2u16xWlrJdugccz795fJBUV9aQSD+8S3KeqwQhoi8RK1uhD68aGCyaSpBq0NZ8COAkn7MXaF4POxrAAt8udfHM+PRfSOptcH/w==" To sBase64_rsa_sig
// 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 against the signature.
Set ComEncodingMode Of hoRsa To "base64"
Get ComVerifyHashENC Of hoRsa sSha256_base64 "sha256" sBase64_rsa_sig 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