Sample code for 30+ languages & platforms
PureBasic

RSA Import Public Key

See more RSA Examples

Shows how to select/import a public key for RSA encryption or signature verification.

Chilkat PureBasic Downloads

PureBasic
IncludeFile "CkPublicKey.pb"
IncludeFile "CkRsa.pb"

Procedure ChilkatExample()

    success.i = 0

    pubKey.i = CkPublicKey::ckCreate()
    If pubKey.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    ; In all Chilkat methods expecting a path, you pass either absolute or relative paths.
    success = CkPublicKey::ckLoadFromFile(pubKey,"rsaKeys/myTestRsaPublic.pem")
    If success = 0
        Debug CkPublicKey::ckLastErrorText(pubKey)
        CkPublicKey::ckDispose(pubKey)
        ProcedureReturn
    EndIf

    rsa.i = CkRsa::ckCreate()
    If rsa.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    ; Tell RSA to use the public key.
    CkRsa::ckUsePublicKey(rsa,pubKey)


    CkPublicKey::ckDispose(pubKey)
    CkRsa::ckDispose(rsa)


    ProcedureReturn
EndProcedure