Sample code for 30+ languages & platforms
DataFlex

RSASSA-PSS Algorithm with SHA256 Hashing

See more RSA Examples

RSA encrypt a SHA256 hash with OAEP padding.

Chilkat DataFlex Downloads

DataFlex
Use ChilkatAx-win32.pkg

Procedure Test
    Boolean iSuccess
    Variant vPrivkey
    Handle hoPrivkey
    Handle hoRsa
    String sSigStr
    String sTemp1
    Boolean bTemp1

    Move False To iSuccess

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

    Get Create (RefClass(cComChilkatPrivateKey)) To hoPrivkey
    If (Not(IsComObjectCreated(hoPrivkey))) Begin
        Send CreateComObject of hoPrivkey
    End

    // Load the private key object from a PEM file.
    // (To load from a PEM string, call LoadPem instead.)
    Get ComLoadPemFile Of hoPrivkey "somePath/myPrivateKey.pem" To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoPrivkey To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get Create (RefClass(cComChilkatRsa)) To hoRsa
    If (Not(IsComObjectCreated(hoRsa))) Begin
        Send CreateComObject of hoRsa
    End
    // Use RSA-PSS by setting PkcsPadding = False
    Set ComPkcsPadding Of hoRsa To False
    // Use SHA256
    Set ComOaepHash Of hoRsa To "SHA-256"

    Get pvComObject of hoPrivkey to vPrivkey
    Get ComUsePrivateKey Of hoRsa vPrivkey To iSuccess

    // Generate a base64 signature.
    Set ComEncodingMode Of hoRsa To "base64"

    Get ComSignStringENC Of hoRsa "String to be signed" "SHA-256" To sSigStr
    Get ComLastMethodSuccess Of hoRsa To bTemp1
    If (bTemp1 = False) Begin
        Get ComLastErrorText Of hoRsa To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Showln "Signature: " sSigStr


End_Procedure