Chilkat Examples

ChilkatHOME.NET Core C#Android™AutoItCC#C++Chilkat2-PythonCkPythonClassic ASPDataFlexDelphi ActiveXDelphi DLLGoJavaLianjaMono C#Node.jsObjective-CPHP ActiveXPHP ExtensionPerlPowerBuilderPowerShellPureBasicRubySQL ServerSwift 2Swift 3,4,5...TclUnicode CUnicode C++VB.NETVBScriptVisual Basic 6.0Visual FoxProXojo Plugin

PHP ActiveX Examples

Web API Categories

ASN.1
AWS KMS
AWS Misc
Amazon EC2
Amazon Glacier
Amazon S3
Amazon S3 (new)
Amazon SES
Amazon SNS
Amazon SQS
Async
Azure Cloud Storage
Azure Key Vault
Azure Service Bus
Azure Table Service
Base64
Bounced Email
Box
CAdES
CSR
CSV
Certificates
Cloud Signature CSC
Code Signing
Compression
DKIM / DomainKey
DNS
DSA
Diffie-Hellman
Digital Signatures
Dropbox
Dynamics CRM
EBICS
ECC
Ed25519
Email Object
Encryption
FTP
FileAccess
Firebase
GMail REST API
GMail SMTP/IMAP/POP
Geolocation
Google APIs
Google Calendar
Google Cloud SQL
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
MS Storage Providers
Microsoft Graph
Misc
NTLM
OAuth1
OAuth2
OIDC
Office365
OneDrive
OpenSSL
Outlook
Outlook Calendar
Outlook Contact
PDF Signatures
PEM
PFX/P12
PKCS11
POP3
PRNG
REST
REST Misc
RSA
SCP
SCard
SFTP
SMTP
SSH
SSH Key
SSH Tunnel
ScMinidriver
SharePoint
SharePoint Online
Signing in the Cloud
Socket/SSL/TLS
Spider
Stream
Tar Archive
ULID/UUID
Upload
WebSocket
XAdES
XML
XML Digital Signatures
XMP
Zip
curl
uncategorized

 

 

 

(PHP ActiveX) Get Public Key in Format for ~/.ssh/authorized_keys

If you have an RSA private key, then by definition you also have the public key because the RSA public key is a subset of the private key. (The public key is just the modulus + exponent, whereas the private key contains additional items.)

This example converts an RSA private key to the OpenSSH format public-key (a single line of text) that can be inserted into the ~/.ssh/authorized_keys file on the SSH server to enable public-key authentication for a particular private key.

Note: On the SSH server, such as on a Ubuntu Linux computer, the sshd config file is located at /etc/ssh/sshd_config. It contains a line that indicates the authorized keys file, and the typical default is:

AuthorizedKeysFile      .ssh/authorized_keys

Chilkat ActiveX Downloads

ActiveX for 32-bit and 64-bit Windows

Note: The php_com_dotnet.dll may need to be enabled inside of php.ini.

<?php

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

// Load a private key from a file.  The format can be text format, such as .ppk (PuTTY private key) or .pem.
$privateKeyPath = '/myKeys/myRsaKey.ppk';

// Here's an example of a non-encrypted private key in ppk format:

// PuTTY-User-Key-File-3: ssh-rsa
// Encryption: none
// Comment: rsa-key-20220606
// Public-Lines: 6
// AAAAB3NzaC1yc2EAAAADAQABAAABAQDKQUdx8EU6qIpVcT1NbL/sSnELJdifQa+K
// kOqvgKIU30wIwGMfigSeiTFXw2jWsPcMyOIRKUvR3nf8wtR6NEj3qDfGUo3b/8Fx
// 5BHDKuR5uU0ZJmv3Am+/hSPWOJFltL8DkxDLEpGDujLwGiUbpD9SADYhhvk9OBA7
// 0l70hYs9gWJBjm9CR8hPg3b3F7gOYljAY2dk6W3PGmzQi+D7BTE0yYfhEOoDX7ah
// sgrUnWIiIWK9cqLT8XbAb8gitnCmP0LerxRAkX25O4Gx/uGSrMxO/cRwz5UpiNL2
// cciM7P4vzlbcpQiKrKaBYg5GB84QqE3xCt9cEr/qD235LpSMnWRR
// Private-Lines: 14
// AAABAQClKCE7PUSK3c34b3vrmX4vaapdvA3kHjNGJ4g8wAGaoazpCJDo1D9pZgZQ
// 8FTP27ohSniwItSzD8NTN5ViJQfglBDXddo5Z+ODKQYIJSJk85etjd5j2i1+ay4U
// ZCT2tF22gYUZDpScyJOH1RGwPLMoNtv9DMbB4uH+t46qhdJp6aWvJB7L/HUhnszc
// qbwTG//CDL2j8Y1Mre8zvWBA8cr0I0qCzWD/Xw5MgDgpA444CFGpYb1mt8ghLniT
// hMGgt6scUO/lnBEYo17a9N7wBexvyk0ZgEVo6nweRnCFHijNbG+C82svrsLQuL7g
// o65BcEqLo+wBO+FtutTf2gtevZcBAAAAgQDnt2Freyfn1V93qZar06w7dXn4yV4G
// cvQ3FmJBhk7akEFuZPOceDqrAgzS+TmsH4C96ssETdMxMO4vwEjSnZAatw6TKgnK
// 9aDJL6/uzhk/dmBmyp7iWttN9QW9cRQvLYtwJssNDPUmF1/1cGFMpLyLfTlRBCok
// 8dksYys4FTUfeQAAAIEA33N+LIO8i2U1NNfy2yU5GGJoFaXwPIa/CZNzZ8hbvLwm
// 5yay4MKxGgizX+FhQ/OiEiFDEs1GDssKTXaqhE9mI/vKKLGYj9wEiWhwnawx56GI
// WhdTZPtWkU4tYj/OkABD8vp973W1k4NEjYxVg8AoZZL1Kr4zturV8KJl9v4b/ZkA
// AACBANAijbBLPxSTdyG9duZT89+jIdgjdjVdV5UL/xZLEh6pWbHludZHItXl62G7
// luuJbiqhx2FANxhSu7/tAEX3z2jx7ari51Ddf/+sqfrLwc3dPkU8YXpUNYJIaNFR
// LyzMMZvL2sPxnE6dxt4nR761y+EnTZpZ2oeSC21Lzq2xKcBp
// Private-MAC: e0c3b5eba925944355d8d63fefcec02a982c7281a87e9994c04ce956b5c3e69b

// For versions of Chilkat < 10.0.0, use new COM('Chilkat_9_5_0.Chilkat.StringBuilder')
$sbKey = new COM("Chilkat.StringBuilder");
$success = $sbKey->LoadFile($privateKeyPath,'utf-8');
if ($success == 0) {
    print 'Failed to load the private key from a file.' . "\n";
    exit;
}

// For versions of Chilkat < 10.0.0, use new COM('Chilkat_9_5_0.Chilkat.SshKey')
$key = new COM("Chilkat.SshKey");

// If the private key file is encrypted, then you'll need to set a password.
// If it's not encrypted, the password here is ignored.
$key->Password = 'private_key_password';

// The FromPuttyPrivateKey method will actually auto-detect the format and correctly load any string-based format.
// For example, you can pass in a PEM private key.
$success = $key->FromPuttyPrivateKey($sbKey->getAsString());
if ($success == 0) {
    print $key->LastErrorText . "\n";
    exit;
}

// Get the public key in OpenSSH format:
$pubKeyStr = $key->toOpenSshPublicKey();
print $pubKeyStr . "\n";

// Sample output:
// ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDKQUdx8EU6qIpVcT1NbL/sSnELJdifQa+KkOqvgKIU30wIwGMfigSeiTFXw2jWsPcMyOIRKUvR3nf8wtR6NEj3qDfGUo3b/8Fx5BHDKuR5uU0ZJmv3Am+/hSPWOJFltL8DkxDLEpGDujLwGiUbpD9SADYhhvk9OBA70l70hYs9gWJBjm9CR8hPg3b3F7gOYljAY2dk6W3PGmzQi+D7BTE0yYfhEOoDX7ahsgrUnWIiIWK9cqLT8XbAb8gitnCmP0LerxRAkX25O4Gx/uGSrMxO/cRwz5UpiNL2cciM7P4vzlbcpQiKrKaBYg5GB84QqE3xCt9cEr/qD235LpSMnWRR rsa-key-20220606

// To authorize the private key for a particular SSH user account, copy the above public key into the ~/.ssh/authorized_keys file.
// If authorized_keys already contains some keys, you can append it to a new line in the file.

?>

 

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