Sample code for 30+ languages & platforms
PowerBuilder

Duplicate openssl rsautl -verify -inkey pubKey.pem -pubin -in rsautl.sig -out originalFile.dat

See more OpenSSL Examples

Demonstrates how to duplicate this OpenSSL command:
openssl rsautl -verify -inkey pubKey.pem -pubin -in rsautl.sig -out originalFile.dat
The signature file contains the contents of the original data, and the original data is output to "originalFile.dat".

The openssl rsautl command signs the data directly, and therefore the maximum amount of data that can signed is very small. (To sign any amount of data, use openssl dgst -sign.) The maximum amount of data that can be signed (with rsautl) is the key size minus the overhead for the padding. The overhead size depends on the padding. With OAEP padding, the overhead is 42 bytes. With the default PKCSv1.5 padding, the overhead is 11 bytes.

Given a 2048-bit RSA key (256 bytes) and using PKCSv1.5 padding, the max data size that can be signed is 256 - 11 = 245 bytes.

Chilkat PowerBuilder Downloads

PowerBuilder
integer li_rc
integer li_Success
oleobject loo_PubKey
oleobject loo_Bd
oleobject loo_Rsa

li_Success = 0

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

loo_PubKey = create oleobject
li_rc = loo_PubKey.ConnectToNewObject("Chilkat.PublicKey")
if li_rc < 0 then
    destroy loo_PubKey
    MessageBox("Error","Connecting to COM object failed")
    return
end if

// Load the public key from an PEM file:
li_Success = loo_PubKey.LoadFromFile("pubKey.pem")
if li_Success = 0 then
    Write-Debug loo_PubKey.LastErrorText
    destroy loo_PubKey
    return
end if

// Load the signature.
loo_Bd = create oleobject
li_rc = loo_Bd.ConnectToNewObject("Chilkat.BinData")

li_Success = loo_Bd.LoadFile("rsautl.sig")

loo_Rsa = create oleobject
li_rc = loo_Rsa.ConnectToNewObject("Chilkat.Rsa")

// Import the public key into the RSA component:
li_Success = loo_Rsa.UsePublicKey(loo_PubKey)
if li_Success = 0 then
    Write-Debug loo_Rsa.LastErrorText
    destroy loo_PubKey
    destroy loo_Bd
    destroy loo_Rsa
    return
end if

// OpenSSL uses big-endian.
loo_Rsa.LittleEndian = 0

// If the signature is verified, then the signature contents of bd
// are replaced with the extracted original data.
li_Success = loo_Rsa.VerifyRawBd(loo_Bd)
if li_Success <> 1 then
    Write-Debug loo_Rsa.LastErrorText
    Write-Debug "The signature was invalid."
    destroy loo_PubKey
    destroy loo_Bd
    destroy loo_Rsa
    return
end if

Write-Debug "The signature was verified."

// Save the original data that was extracted from the signature:
li_Success = loo_Bd.WriteFile("originalFile.dat")
if li_Success <> 1 then
    Write-Debug "Failed to save extracted data."
    destroy loo_PubKey
    destroy loo_Bd
    destroy loo_Rsa
    return
end if



destroy loo_PubKey
destroy loo_Bd
destroy loo_Rsa