Chilkat Examples

ChilkatHOMEAndroid™Classic ASPCC++C#Mono C#.NET Core C#C# UWP/WinRTDataFlexDelphi ActiveXDelphi DLLVisual FoxProJavaLianjaMFCObjective-CPerlPHP ActiveXPHP ExtensionPowerBuilderPowerShellPureBasicPythonRubySQL ServerSwiftTclUnicode CUnicode C++Visual Basic 6.0VB.NETVB.NET UWP/WinRTVBScriptXojo PluginNode.jsExcel

C++ Examples


ASN.1
Amazon S3
Amazon S3 (new)
Amazon SES
Amazon SNS
Amazon SQS
Async
Azure Cloud Storage
Azure Service Bus
Bounced Email
Box
CSR
CSV
Certificates
Compression
DKIM / DomainKey
DSA
Diffie-Hellman
Digital Signatures
Dropbox
Dynamics CRM
ECC
Email Object
Encryption
FTP
Facebook
Firebase
GeoOp
Google APIs
Google Calendar
Google Cloud Storage
Google Drive
Gzip
HTML-to-XML/Text
HTTP
HTTP Misc
IMAP
JSON
JSON Web Encryption (JWE)
JSON Web Signatures (JWS)
JSON Web Token (JWT)
Java KeyStore (JKS)

Jira
MHT / HTML Email
MIME
Microsoft Graph
NTLM
OAuth1
OAuth2
OneDrive
OpenSSL
Outlook
PEM
PFX/P12
POP3
PRNG
PayPal
Peoplevox
QuickBooks
REST
REST Misc
RSA Encryption
SCP
SFTP
SMTP
SSH
SSH Key
SSH Tunnel
SharePoint
Shopify
Socket/SSL/TLS
Spider
Stream
Stripe
SugarCRM
Tar Archive
Twitter
VoiceBase
Walmart
WebSocket
XAdES
XML
XML Digital Signatures
XMP
Xero
Zip
curl
eBay

 

 

 

(C++) Duplicate openssl rsautl -sign -in small.dat -inkey private.pem -out rsautl.sig

Demonstrates how to duplicate this OpenSSL command:

openssl rsautl -sign -in small.dat -inkey private.pem -out rsautl.sig
The small.dat file is a small file that can contain text or binary data of any type. The "openssl rsautl" command is different than "openssl dgst -sign" because it signs the input data directly with the RSA algorithm. The "openssl dgst -sign" command first digests the input data and then signs the digest.

How much data can be signed with "openssl rsautl"? The maximum size (in bytes) 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 C/C++ Library Downloads

MS Visual C/C++

Linux/CentOS/Heroku C/C++

MAC OS X C/C++

C++ Builder

Solaris C/C++

iOS C/C++

Android C/C++

Raspberry Pi C/C++

Windows Mobile 5.0/Pocket PC 2003

ARM Embedded Linux C/C++

PowerLinux C/C++

FreeBSD C/C++

MinGW C/C++

#include <CkPrivateKey.h>
#include <CkByteData.h>
#include <CkRsa.h>

void ChilkatSample(void)
    {
    bool success;

    CkPrivateKey pkey;

    //  Load the private key from an PEM file:
    success = pkey.LoadPemFile("private.pem");
    if (success != true) {
        std::cout << pkey.lastErrorText() << "\r\n";
        return;
    }

    //  Load the file to be signed.
    CkByteData inData;
    success = inData.loadFile("small.dat");
    if (success != true) {
        std::cout << "Failed to load input data." << "\r\n";
        return;
    }

    CkRsa rsa;

    //  Any string argument automatically begins the 30-day trial.
    success = rsa.UnlockComponent("Anything for 30-day trial");
    if (success != true) {
        std::cout << rsa.lastErrorText() << "\r\n";
        return;
    }

    //  Import the private key into the RSA component:
    success = rsa.ImportPrivateKeyObj(pkey);
    if (success != true) {
        std::cout << rsa.lastErrorText() << "\r\n";
        return;
    }

    //  OpenSSL uses big-endian...
    rsa.put_LittleEndian(false);

    CkByteData sigData;
    success = rsa.OpenSslSignBytes(inData,sigData);
    if (success != true) {
        std::cout << rsa.lastErrorText() << "\r\n";
        return;
    }

    //  Save the binary signature to a file.
    success = sigData.saveFile("rsautl.sig");
    if (success != true) {
        std::cout << "Failed to save signature file." << "\r\n";
        return;
    }

    std::cout << "Success." << "\r\n";

    }

 

© 2000-2016 Chilkat Software, Inc. All Rights Reserved.