Sample code for 30+ languages & platforms
PureBasic

RSA Import Private Key

See more RSA Examples

Shows how to select/import a private key for RSA signing or decryption.

Chilkat PureBasic Downloads

PureBasic
IncludeFile "CkPrivateKey.pb"
IncludeFile "CkRsa.pb"

Procedure ChilkatExample()

    success.i = 0

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

    password.s = "secret"
    ; In all Chilkat methods expecting a path, you pass either absolute or relative paths.
    success = CkPrivateKey::ckLoadAnyFormatFile(privKey,"rsaKeys/myTestRsaPrivate.pem",password)
    If success = 0
        Debug CkPrivateKey::ckLastErrorText(privKey)
        CkPrivateKey::ckDispose(privKey)
        ProcedureReturn
    EndIf

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

    ; Tell the RSA object to use the private key (i.e. import the private key)
    CkRsa::ckUsePrivateKey(rsa,privKey)


    CkPrivateKey::ckDispose(privKey)
    CkRsa::ckDispose(rsa)


    ProcedureReturn
EndProcedure