Lianja
Lianja
RSA Encrypt with Modulus and Exponent
See more RSA Examples
Demonstrates how to RSA encrypt with a given modulus and exponent.Chilkat Lianja Downloads
llSuccess = .F.
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
loRsa = createobject("CkRsa")
// 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("CkXml")
loXml.Tag = "RSAPublicKey"
loXml.NewChild2("Modulus",lcModulus)
loXml.NewChild2("Exponent",lcExponent)
loPubKey = createobject("CkPublicKey")
llSuccess = loPubKey.LoadFromString(loXml)
if (llSuccess = .F.) then
? loPubKey.LastErrorText
release loRsa
release loXml
release loPubKey
return
endif
llSuccess = loRsa.UsePublicKey(loPubKey)
if (llSuccess = .F.) then
? loRsa.LastErrorText
release loRsa
release loXml
release loPubKey
return
endif
llUsePrivateKey = .F.
lcPlainText = "message in a bottle"
loRsa.EncodingMode = "base64"
lcEncryptedStrBase64 = loRsa.EncryptStringENC(lcPlainText,llUsePrivateKey)
? lcEncryptedStrBase64
release loRsa
release loXml
release loPubKey