Sample code for 30+ languages & platforms
Xbase++ Requires Chilkat v11.0.0+

RSA Sign using Base64 Private Key

See more RSA Examples

Signs a string using a non-encrypted RSA private key in base64 encoding. Returns the RSA signature as a base64 string.

Chilkat Xbase++ Downloads

Xbase++
LOCAL nSuccess
LOCAL oPrivKey
LOCAL oSbPem
LOCAL oRsa
LOCAL oBd
LOCAL cStrOriginal

nSuccess := 0

//  This requires the Chilkat API to have been previously unlocked.
//  See Global Unlock Sample for sample code.

oPrivKey := CreateObject("Chilkat.PrivateKey")

oSbPem := CreateObject("Chilkat.StringBuilder")
oSbPem:AppendLine("-----BEGIN RSA PRIVATE KEY-----", 1)
oSbPem:AppendLine("MIIC .... j5A==", 1)
oSbPem:AppendLine("-----END RSA PRIVATE KEY-----", 1)

nSuccess := oPrivKey:LoadPem(oSbPem:GetAsString())
IF (nSuccess == 0)
    ? oPrivKey:LastErrorText
    oPrivKey:destroy()
    oSbPem:destroy()
    RETURN
ENDIF

oRsa := CreateObject("Chilkat.Rsa")

nSuccess := oRsa:UsePrivateKey(oPrivKey)
IF (nSuccess == 0)
    ? oRsa:LastErrorText
    oPrivKey:destroy()
    oSbPem:destroy()
    oRsa:destroy()
    RETURN
ENDIF

oBd := CreateObject("Chilkat.BinData")
oBd:AppendString("12345678", "utf-8")

nSuccess := oRsa:SignRawBd(oBd)
IF (nSuccess == 0)
    ? oRsa:LastErrorText
    oPrivKey:destroy()
    oSbPem:destroy()
    oRsa:destroy()
    oBd:destroy()
    RETURN
ENDIF

//  Get the base64 RSA signature.
? oBd:GetEncoded("base64")

nSuccess := oRsa:VerifyRawBd(oBd)
IF (nSuccess == 0)
    ? oRsa:LastErrorText
    oPrivKey:destroy()
    oSbPem:destroy()
    oRsa:destroy()
    oBd:destroy()
    RETURN
ENDIF

cStrOriginal := oBd:GetString("utf-8")
? cStrOriginal

oPrivKey:destroy()
oSbPem:destroy()
oRsa:destroy()
oBd:destroy()