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
(PureBasic) openssl smime -encrypt -des3 -in
See more OpenSSL ExamplesOpenSSL SMIME encrypt file using PEM containing a certificate.
IncludeFile "CkBinData.pb" IncludeFile "CkCert.pb" IncludeFile "CkStringBuilder.pb" IncludeFile "CkCrypt2.pb" IncludeFile "CkPem.pb" Procedure ChilkatExample() ; This example requires the Chilkat API to have been previously unlocked. ; See Global Unlock Sample for sample code. ; Load the cert from a PEM file. pem.i = CkPem::ckCreate() If pem.i = 0 Debug "Failed to create object." ProcedureReturn EndIf ; Our particular PEM was not encrypted, so we pass an empty password. ; Also, a private key is not needed for encryption. The PEM used to test this example ; happens to have a private key, but it's not actually used. success.i = CkPem::ckLoadPemFile(pem,"qa_data/openssl/rsaCertAndKey.pem","") If success = 0 Debug CkPem::ckLastErrorText(pem) CkPem::ckDispose(pem) ProcedureReturn EndIf If CkPem::ckNumCerts(pem) = 0 Debug "PEM does not contain any certificates." CkPem::ckDispose(pem) ProcedureReturn EndIf cert.i = CkPem::ckGetCert(pem,0) If CkPem::ckLastMethodSuccess(pem) = 0 Debug CkPem::ckLastErrorText(pem) CkPem::ckDispose(pem) ProcedureReturn EndIf ; ------------------------------------------------------------------------------------- ; Duplicate this OpenSSL command: openssl smime -encrypt -des3 -in <file> <pem file> ; ------------------------------------------------------------------------------------- crypt.i = CkCrypt2::ckCreate() If crypt.i = 0 Debug "Failed to create object." ProcedureReturn EndIf success = CkCrypt2::ckSetEncryptCert(crypt,cert) If success = 0 Debug CkCrypt2::ckLastErrorText(crypt) CkCert::ckDispose(cert) CkPem::ckDispose(pem) CkCrypt2::ckDispose(crypt) ProcedureReturn EndIf CkCert::ckDispose(cert) CkCrypt2::setCkCryptAlgorithm(crypt, "PKI") CkCrypt2::setCkPkcs7CryptAlg(crypt, "3des") CkCrypt2::setCkKeyLength(crypt, 168) ; Load the file to be encrypted. bd.i = CkBinData::ckCreate() If bd.i = 0 Debug "Failed to create object." ProcedureReturn EndIf success = CkBinData::ckLoadFile(bd,"qa_data/openssl/hello.txt") If success = 0 Debug "Failed to load the input file." CkPem::ckDispose(pem) CkCrypt2::ckDispose(crypt) CkBinData::ckDispose(bd) ProcedureReturn EndIf ; Encrypt. success = CkCrypt2::ckEncryptBd(crypt,bd) If success = 0 Debug CkCrypt2::ckLastErrorText(crypt) CkPem::ckDispose(pem) CkCrypt2::ckDispose(crypt) CkBinData::ckDispose(bd) ProcedureReturn EndIf ; The openssl smime -encrypt command produces encrypte MIME such as this: ; MIME-Version: 1.0 ; Content-Disposition: attachment; filename="smime.p7m" ; Content-Type: application/x-pkcs7-mime; smime-type=enveloped-data; name="smime.p7m" ; Content-Transfer-Encoding: base64 ; ; MIICzwYJKoZIhvcNAQcDoIICwDCCArwCAQAxggF8MIIBeAIBADBgMEoxCzAJBgNVBAYTAlVTMRYw ; FAYDVQQKEw1MZXQncyBFbmNyeXB0MSMwIQYDVQQDExpMZXQncyBFbmNyeXB0IEF1dGhvcml0eSBY ; MwISA9Nqgb1dH/XTDNeKzN1nR85iMA0GCSqGSIb3DQEBAQUABIIBAIQqPexjxWovgxwKV/r3HL/U ; EP9Yozvz5hBeX5VvRZjKSi4FRw5wapElPK+4FB82hiAR9Mi3c16PvPSVkJv3l78Mv5uaaOs/OmUz ; mIHFB6Z+l2E52BDmUVWJZTQ09vdWy6+NIRlg2R9Z1NkmZ4BZCJk6mHB/Yx03IaOxK8LnwieDMthM ; SvxbhJnIOISN7k7ofs+/0vTXUpdQ+tlmwyVySMGQ6VMk+z4sqZJ2stacqCPtt/aiSwJ9p0OKmihf ; 3KDJceXJtavIQeA97yz1LqPvle35mmd5sBhV9qQYdTV/KJ+YM5uEZ9BHYbvMJbADFHwKzhcEY3qA ; 7T9acmEsb7NycOIwggE1BgkqhkiG9w0BBwEwFAYIKoZIhvcNAwcECERX/ZoHweSkgIIBEMmCMx49 ; zjVAnGqRaBbvzQT1hg0uQSxIJjxMxC+HSuM+eY9oSOsbrw4uIijHKH9NdOpeDsdRzg2z5EBM7AlP ; Ht9DyPW5C2deV6RPX4F8gyExz+JUXrd+3Yb3AKTdpDkTWDmNCeO0r/YSqp518+mfU5hG8e336u51 ; HAM44FeknA8oThWsD/wUB1e8vzsatK4UXW/KSu/166V7z+VT86kd+IHa7t60U9Yp0ZXgcM5Pb5Ni ; 69Qc5MKPzom2801H5UR/WjCgsxOIjOj49sKisjRy79skrJzxY5ZG05T0dKn6KC3TjRpIEEeOyhCd ; Nm2Y7dcW8GLMepdhWay5vePmQxmvmhbAtBprIem14NcrYeG6D5wP ; We have the body in bd ; Construct the header and base64 body... sbEncryptedMime.i = CkStringBuilder::ckCreate() If sbEncryptedMime.i = 0 Debug "Failed to create object." ProcedureReturn EndIf CkStringBuilder::ckAppendLine(sbEncryptedMime,"MIME-Version: 1.0",1) CkStringBuilder::ckAppendLine(sbEncryptedMime,"Content-Disposition: attachment; filename=" + Chr(34) + "smime.p7m" + Chr(34),1) CkStringBuilder::ckAppendLine(sbEncryptedMime,"Content-Type: application/x-pkcs7-mime; smime-type=enveloped-data; name=" + Chr(34) + "smime.p7m" + Chr(34),1) CkStringBuilder::ckAppendLine(sbEncryptedMime,"Content-Transfer-Encoding: base64",1) CkStringBuilder::ckAppendLine(sbEncryptedMime,"",1) CkStringBuilder::ckAppendLine(sbEncryptedMime,CkBinData::ckGetEncoded(bd,"base64_mime"),1) ; Show the result. Debug CkStringBuilder::ckGetAsString(sbEncryptedMime) ; or save to a file.. success = CkStringBuilder::ckWriteFile(sbEncryptedMime,"qa_output/encryptedMime.txt","utf-8",0) CkPem::ckDispose(pem) CkCrypt2::ckDispose(crypt) CkBinData::ckDispose(bd) CkStringBuilder::ckDispose(sbEncryptedMime) ProcedureReturn EndProcedure |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.