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

PowerShell 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

 

 

 

(PowerShell) Load Certificate from Smart Card by Key Usage

See more Certificates Examples

You may have a smartcard or USB token that contains only 2 certificates, one for signing, and one for authentication, and you wish to load the certificate for signing. This example demonstrates how to load the 1st certificate found on a smartcard that matches the intended key usage.

Chilkat .NET Downloads

Chilkat .NET Assemblies

Add-Type -Path "C:\chilkat\ChilkatDotNet47-9.5.0-x64\ChilkatDotNet47.dll"

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

$cert = New-Object Chilkat.Cert

# If you know the smart card PIN, set it prior to loading from the smartcard/USB token.
$cert.SmartCardPin = "12345678"

# To load a certificate matching an intended key usage, specify the type of usage as shown below.
# 
# The possible key usage keywords are:
# 
# digitalsignature
# Use when the public key is used with a digital signature mechanism to support security services other than non-repudiation, certificate signing, or CRL signing. 
# A digital signature is often used for entity authentication and data origin authentication with integrity.

# nonrepudiation
# When a digital certificate's key usage includes "nonrepudiation," it implies that the certificate and its associated private key can be used to 
# create digital signatures that provide proof of the origin and integrity of the signed data, and the signer cannot later deny having signed the data.

# Other less common usages:

# certificatesigning
# keyencipherment
# dataencipherment
# crlsigning
# secureemail
# serverauthentication
# clientauthentication
# codesigning
# timestamping

$success = $cert.LoadFromSmartcard("keyusage=nonrepudiation")
if ($success -eq $false) {
    $($cert.LastErrorText)
    $("Certificate not loaded.")
    exit
}

$("Found: " + $cert.SubjectDN + " serial=" + $cert.SerialNumber)

 

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