Visual FoxPro
Visual FoxPro
RSA Hash Binary Data and Sign (and Verify)
See more RSA Examples
Demonstrates how to sign the hash of binary data. Also demonstrates how to verify the RSA signature.Chilkat Visual FoxPro Downloads
LOCAL lnSuccess
LOCAL loPrivKey
LOCAL loRsa
LOCAL lcOriginalData
LOCAL loBdData
LOCAL loBdSignature
LOCAL loPubKey
LOCAL loRsa2
LOCAL lnBVerified
lnSuccess = 0
* This example requires the Chilkat API to have been previously unlocked.
* See Global Unlock Sample for sample code.
* Load an RSA private key for signing.
loPrivKey = CreateObject('Chilkat.PrivateKey')
lnSuccess = loPrivKey.LoadEncryptedPemFile("qa_data/pem/rsa_passwd.pem","passwd")
IF (lnSuccess = 0) THEN
? loPrivKey.LastErrorText
RELEASE loPrivKey
CANCEL
ENDIF
loRsa = CreateObject('Chilkat.Rsa')
loRsa.UsePrivateKey(loPrivKey)
* We have some binary data (in hex) to sign
lcOriginalData = "0102030405060708090A"
loBdData = CreateObject('Chilkat.BinData')
loBdData.AppendEncoded(lcOriginalData,"hex")
* Hash (SHA-256) and sign the hash:
loBdSignature = CreateObject('Chilkat.BinData')
lnSuccess = loRsa.SignBd(loBdData,"sha256",loBdSignature)
IF (lnSuccess = 0) THEN
? loRsa.LastErrorText
RELEASE loPrivKey
RELEASE loRsa
RELEASE loBdData
RELEASE loBdSignature
CANCEL
ENDIF
* Show the RSA signature in base64
? loBdSignature.GetEncoded("base64")
* ------------------------------------------
* Get the public key from the private key
loPubKey = CreateObject('Chilkat.PublicKey')
loPrivKey.ToPublicKey(loPubKey)
* Verify the signature..
loRsa2 = CreateObject('Chilkat.Rsa')
loRsa2.UsePublicKey(loPubKey)
lnBVerified = loRsa2.VerifyBd(loBdData,"sha256",loBdSignature)
? "signature verified: " + STR(lnBVerified)
RELEASE loPrivKey
RELEASE loRsa
RELEASE loBdData
RELEASE loBdSignature
RELEASE loPubKey
RELEASE loRsa2