Visual FoxPro
Visual FoxPro
RSA Encrypt with Modulus and Exponent
See more RSA Examples
Demonstrates how to RSA encrypt with a given modulus and exponent.Chilkat Visual FoxPro Downloads
LOCAL lnSuccess
LOCAL loRsa
LOCAL lcModulus
LOCAL lcExponent
LOCAL loXml
LOCAL loPubKey
LOCAL lnUsePrivateKey
LOCAL lcPlainText
LOCAL lcEncryptedStrBase64
lnSuccess = 0
* This example assumes the Chilkat API to have been previously unlocked.
* See Global Unlock Sample for sample code.
loRsa = CreateObject('Chilkat.Rsa')
* Assuming you already have a base64 modulus and exponent,
* wrap it in XML like this:
lcModulus = "qMBRpdYrAy5aMmo31NErUizh5sbweguSmh4wlK6uJEIDl+kwTlROnE34KOFExeTbJSX0WygPi+vWl0yNq7buIMUKpytossAAWut5khO3CQJxTk7G2gnEPNUUXHiExGgNrLzcSLv8YIlfVALhoRWyC67KOL+a+3taNq3h+BHeWhM="
lcExponent = "AQAB"
loXml = CreateObject('Chilkat.Xml')
loXml.Tag = "RSAPublicKey"
loXml.NewChild2("Modulus",lcModulus)
loXml.NewChild2("Exponent",lcExponent)
loPubKey = CreateObject('Chilkat.PublicKey')
lnSuccess = loPubKey.LoadFromString(loXml)
IF (lnSuccess = 0) THEN
? loPubKey.LastErrorText
RELEASE loRsa
RELEASE loXml
RELEASE loPubKey
CANCEL
ENDIF
lnSuccess = loRsa.UsePublicKey(loPubKey)
IF (lnSuccess = 0) THEN
? loRsa.LastErrorText
RELEASE loRsa
RELEASE loXml
RELEASE loPubKey
CANCEL
ENDIF
lnUsePrivateKey = 0
lcPlainText = "message in a bottle"
loRsa.EncodingMode = "base64"
lcEncryptedStrBase64 = loRsa.EncryptStringENC(lcPlainText,lnUsePrivateKey)
? lcEncryptedStrBase64
RELEASE loRsa
RELEASE loXml
RELEASE loPubKey