Sample code for 30+ languages & platforms
Visual FoxPro

Verfies an RSA Signature

See more Apple Keychain Examples

Verifies an RSA signature against the original data.

Chilkat Visual FoxPro Downloads

Visual FoxPro
LOCAL lnSuccess
LOCAL loBd
LOCAL i
LOCAL loBdSig
LOCAL loPubKey
LOCAL loRsa

lnSuccess = 0

* The following data was signed by the following example:
* RSA Sign using a Private Key on a USB Token or Smartcard
loBd = CreateObject('Chilkat.BinData')

FOR i = 0 TO 100
    loBd.AppendEncoded("000102030405060708090A0B0C0D0E0F","hex")
NEXT

* Load the signature
loBdSig = CreateObject('Chilkat.BinData')
lnSuccess = loBdSig.LoadFile("rsaSignatures/test1.sig")
IF (lnSuccess = 0) THEN
    ? "Failed to load the RSA signature"
    RELEASE loBd
    RELEASE loBdSig
    CANCEL
ENDIF

* Get the public key to be used for signature verification.
loPubKey = CreateObject('Chilkat.PublicKey')
lnSuccess = loPubKey.LoadFromFile("rsaKeys/chilkat-rsa-2048.pem")
IF (lnSuccess = 0) THEN
    ? loPubKey.LastErrorText
    RELEASE loBd
    RELEASE loBdSig
    RELEASE loPubKey
    CANCEL
ENDIF

loRsa = CreateObject('Chilkat.Rsa')
lnSuccess = loRsa.UsePublicKey(loPubKey)
IF (lnSuccess = 0) THEN
    ? loRsa.LastErrorText
    RELEASE loBd
    RELEASE loBdSig
    RELEASE loPubKey
    RELEASE loRsa
    CANCEL
ENDIF

* 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.
lnSuccess = loRsa.VerifyBd(loBd,"sha256",loBdSig)

IF (lnSuccess = 0) THEN
    ? loRsa.LastErrorText
    ? "Signature invalid."
ELSE
    ? "Signature valid."
ENDIF

RELEASE loBd
RELEASE loBdSig
RELEASE loPubKey
RELEASE loRsa