Sample code for 30+ languages & platforms
Lianja

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 Lianja Downloads

Lianja
llSuccess = .F.

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

loPrivKey = createobject("CkPrivateKey")

loSbPem = createobject("CkStringBuilder")
loSbPem.AppendLine("-----BEGIN RSA PRIVATE KEY-----",.T.)
loSbPem.AppendLine("MIIC .... j5A==",.T.)
loSbPem.AppendLine("-----END RSA PRIVATE KEY-----",.T.)

llSuccess = loPrivKey.LoadPem(loSbPem.GetAsString())
if (llSuccess = .F.) then
    ? loPrivKey.LastErrorText
    release loPrivKey
    release loSbPem
    return
endif

loRsa = createobject("CkRsa")

llSuccess = loRsa.UsePrivateKey(loPrivKey)
if (llSuccess = .F.) then
    ? loRsa.LastErrorText
    release loPrivKey
    release loSbPem
    release loRsa
    return
endif

loBd = createobject("CkBinData")
loBd.AppendString("12345678","utf-8")

llSuccess = loRsa.SignRawBd(loBd)
if (llSuccess = .F.) then
    ? loRsa.LastErrorText
    release loPrivKey
    release loSbPem
    release loRsa
    release loBd
    return
endif

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

llSuccess = loRsa.VerifyRawBd(loBd)
if (llSuccess = .F.) then
    ? loRsa.LastErrorText
    release loPrivKey
    release loSbPem
    release loRsa
    release loBd
    return
endif

lcStrOriginal = loBd.GetString("utf-8")
? lcStrOriginal


release loPrivKey
release loSbPem
release loRsa
release loBd