Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(PowerShell) Create PKCS7 Attached/Opaque Signature (S/MIME)Create an S/MIME message with a PKCS7 attached/opaque signature.
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. $mime = New-Object Chilkat.Mime # Load a certificate w/ private key for signing. # There are many ways of getting a certificate object: # from a pfx file, from .cer and private-key files, from the # Windows registry-based certificate stores, etc. # Load a PFX file into a certificate object. $cert = New-Object Chilkat.Cert $pfxFilepath = "pfxFiles/something.pfx" $pfxPassword = "secret" $success = $cert.LoadPfxFile($pfxFilepath,$pfxPassword) if ($success -eq $false) { $($cert.LastErrorText) exit } # Create a very simple MIME message to be signed: $success = $mime.AddHeaderField("Subject","This is a test") $success = $mime.AddHeaderField("MyCustomHeader","abc123") $mime.ContentType = "text/plain" $mime.SetBody("This is a plain-text body.") # Examine the MIME prior to signing: $("--- MIME prior to signing ---") $($mime.GetMime()) # The MIME prior to signing looks like this: # ------------------------------------------------------------------------------- # Subject: This is a test # MyCustomHeader: abc123 # Content-Type: text/plain # # This is a plain-text body. # ------------------------------------------------------------------------------- # The default hash algorithm used in the signing process is "SHA1". # To change it, set the SigningHashAlg property: $mime.SigningHashAlg = "SHA256" # Convert the MIME to PKCS7 signed-data. $success = $mime.ConvertToSigned($cert) if ($success -eq $false) { $($mime.LastErrorText) exit } # Examine the signed MIME $("--- MIME converted to PKCS7 signed-data ---") $($mime.GetMime()) # The MIME after signing looks like this: # ------------------------------------------------------------------------------- # Subject: This is a test # MyCustomHeader: abc123 # Content-Disposition: attachment; filename="smime.p7m" # Content-Transfer-Encoding: base64 # Content-Type: application/x-pkcs7-mime; # name="smime.p7m"; smime-type="signed-data" # # MIIObAYJKoZIhvcNAQcCoIIOXTCCDlkCAQExDzANBglghkgBZQMEAgEFADB2BgkqhkiG9w0BBwGg # aQRnU3ViamVjdDogVGhpcyBpcyBhIHRlc3QNCk15Q3VzdG9tSGVhZGVyOiBhYmMxMjMNCkNvbnRl # bnQtVHlwZTogdGV4dC9wbGFpbg0KDQpUaGlzIGlzIGEgcGxhaW4tdGV4dCBib2R5LqCCCaAwggRm # MIIDTqADAgECAhBEvgyLUAAktBHTNi3gs18bMA0GCSqGSIb3DQEBBQUAMIGVMQswCQYDVQQGEwJV # UzELMAkGA1UECBMCVVQxFzAVBgNVBAcTDlNhbHQgTGFrZSBDaXR5MR4wHAYDVQQKExVUaGUgVVNF # UlRSVVNUIE5ldHdvcmsxITAfBgNVBAsTGGh0dHA6Ly93d3cudXNlcnRydXN0LmNvbTEdMBsGA1UE # AxMUVVROLVVTRVJGaXJzdC1PYmplY3QwHhcNOTkwNzA5MTgzMTIwWhcNMTkwNzA5MTg0MDM2WjCB # lTELMAkGA1UEBhMCVVMxCzAJBgNVBAgTAlVUMRcwFQYDVQQHEw5TYWx0IExha2UgQ2l0eTEeMBwG # A1UEChMVVGhlIFVTRVJUUlVTVCBOZXR3b3JrMSEwHwYDVQQLExhodHRwOi8vd3d3LnVzZXJ0cnVz # dC5jb20xHTAbBgNVBAMTFFVUTi1VU0VSRmlyc3QtT2JqZWN0MIIBIjANBgkqhkiG9w0BAQEFAAOC # AQ8AMIIBCgKCAQEAzqqBP6OjYXiqMQBVlRGeJw8fHN86m4JoMMBKYR3xLw76vnn3pSPvVVGWhM3b # 47luPjHYCiBnx/TZv5TrRwQ+As4qol2HBAn2MJ0Yipeyqhz8QdKhNsv7PZG659lwNfrk55DDm6Ob # 0zz1Epl3sbcJ4GjmHLjzlGOIamr+C3bJvvQi5Ge5qxped8GFB90NbL/uBsd3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BMCVVQxFzAVBgNVBAcTDlNhbHQgTGFrZSBDaXR5MR4wHAYDVQQKExVUaGUgVVNFUlRSVVNU # IE5ldHdvcmsxITAfBgNVBAsTGGh0dHA6Ly93d3cudXNlcnRydXN0LmNvbTEdMBsGA1UEAxMUVVRO # LVVTRVJGaXJzdC1PYmplY3QCEQDm/GiUo2tiCnVnsAEgJ0r7MIG+BgsqhkiG9w0BCRACCzGBrqCB # qzCBlTELMAkGA1UEBhMCVVMxCzAJBgNVBAgTAlVUMRcwFQYDVQQHEw5TYWx0IExha2UgQ2l0eTEe # MBwGA1UEChMVVGhlIFVTRVJUUlVTVCBOZXR3b3JrMSEwHwYDVQQLExhodHRwOi8vd3d3LnVzZXJ0 # cnVzdC5jb20xHTAbBgNVBAMTFFVUTi1VU0VSRmlyc3QtT2JqZWN0AhEA5vxolKNrYgp1Z7ABICdK # +zANBgkqhkiG9w0BAQEFAASCAQBfYh75saVFNXRPOzXOemaoVIFz+OHSsQB1fqXbV+hjGkxuvWAT # ldq32luVFFCz2gErWDT8eZ0yFVVwi16XyP7ptZeGU4cIGtrOozq78dziWwbNB021c3Dcw0vmH83m # FrU8ZNXYhL2+Lu4PlgvSCxHtC9EKrsP0s3WvBk3nMgXhu4Nmvkl1pCAofhAXWs545TfFB3jLEgeR # spbT6PhRR2lErXKF/Ga5NUyUqpw/Ba2YB3fFsbwiMyncmYicnUT2eYxxYBPtX9X6DQSKh3+iLNz0 # sx89fluXIoqWONjR/XyN8zYd6WtEqMMwY6HQPAblFEuMPHZIhC0h/hfGAVisKLmh # # ------------------------------------------------------------------------------ |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.