Chilkat Examples

ChilkatHOMEAndroid™Classic ASPCC++C#Mono C#.NET Core C#C# UWP/WinRTDataFlexDelphi ActiveXDelphi DLLVisual FoxProJavaLianjaMFCObjective-CPerlPHP ActiveXPHP ExtensionPowerBuilderPowerShellPureBasicCkPythonChilkat2-PythonRubySQL ServerSwift 2Swift 3/4TclUnicode CUnicode C++Visual Basic 6.0VB.NETVB.NET UWP/WinRTVBScriptXojo PluginNode.jsExcelGo

Objective-C Examples

Web API Categories

ASN.1
Amazon Glacier
Amazon S3
Amazon S3 (new)
Amazon SES
Amazon SNS
Amazon SQS
Async
Azure Cloud Storage
Azure Service Bus
Base64
Bounced Email
Box
CAdES
CSR
CSV
Certificates
Compression
DKIM / DomainKey
DSA
Diffie-Hellman
Digital Signatures
Dropbox
Dynamics CRM
ECC
Email Object
Encryption
FTP
FileAccess
Firebase
GMail REST API
Geolocation
Google APIs
Google Calendar
Google Cloud Storage
Google Drive
Google Photos
Google Sheets
Google Tasks
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)
MHT / HTML Email
MIME
Microsoft Graph
NTLM
OAuth1
OAuth2
OneDrive
OpenSSL
Outlook
PEM
PFX/P12
POP3
PRNG
REST
REST Misc
RSA Encryption
SCP
SFTP
SMTP
SSH
SSH Key
SSH Tunnel
SharePoint
Socket/SSL/TLS
Spider
Stream
Tar Archive
Upload
WebSocket
XAdES
XML
XML Digital Signatures
XMP
Zip
curl

 

 

 

(Objective-C) Get Public Key from CSR

Demonstrates how to get the public key from a CSR.

Chilkat Objective-C Library Downloads

MAC OS X (Cocoa) Libs

iOS Libs

#import <CkoPem.h>
#import <NSString.h>
#import <CkoAsn.h>
#import <CkoXml.h>
#import <CkoBinData.h>
#import <CkoPublicKey.h>

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

CkoPem *pem = [[CkoPem alloc] init];

//  No password is required.  Pass an empty password string..
NSString *noPassword = @"";
BOOL success = [pem LoadPemFile: @"qa_data/csr/myCsr.pem" password: noPassword];
if (success != YES) {
    NSLog(@"%@",pem.LastErrorText);
    return;
}

NSString *strBase64 = [pem GetEncodedItem: @"csr" itemSubType: @"" encoding: @"base64" index: [NSNumber numberWithInt: 0]];

CkoAsn *asn = [[CkoAsn alloc] init];
success = [asn LoadEncoded: strBase64 encoding: @"base64"];
if (success != YES) {
    NSLog(@"%@",asn.LastErrorText);
    return;
}

//  Convert the ASN.1 to XML.
CkoXml *xml = [[CkoXml alloc] init];
success = [xml LoadXml: [asn AsnToXml]];
NSLog(@"%@",[xml GetXml]);
NSLog(@"%@",@"----");

NSString *strModulusHex = [xml GetChildContent: @"bits"];
NSLog(@"%@%@",@"strModulusHex = ",strModulusHex);
NSLog(@"%@",@"----");

//  We need the modulus as base64.
CkoBinData *bd = [[CkoBinData alloc] init];
[bd AppendEncoded: strModulusHex encoding: @"hex"];
NSString *modulus64 = [bd GetEncoded: @"base64"];
NSLog(@"%@%@",@"modulus64 = ",modulus64);
NSLog(@"%@",@"----");

//  Build the XML for the public key.
CkoXml *xmlPubKey = [[CkoXml alloc] init];
xmlPubKey.Tag = @"RSAPublicKey";
[xmlPubKey UpdateChildContent: @"Modulus" value: modulus64];
//  The RSA exponent will always be decimal 65537 (base64 = AQAB)
[xmlPubKey UpdateChildContent: @"Exponent" value: @"AQAB"];

NSLog(@"%@",@"RSA public key as XML:");
NSLog(@"%@",[xmlPubKey GetXml]);
NSLog(@"%@",@"----");

//  Load the XML into a Chilkat public key object.
CkoPublicKey *pubkey = [[CkoPublicKey alloc] init];
success = [pubkey LoadFromString: [xmlPubKey GetXml]];
if (success != YES) {
    NSLog(@"%@",pubkey.LastErrorText);
    return;
}

//  Show the public key as PEM.
BOOL preferPkcs1 = YES;
NSLog(@"%@",[pubkey GetPem: preferPkcs1]);
 

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