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
(PowerBuilder) Decrypt MIME using RSAES-OAEP with SHA256 and AES-128 content encryptionDemonstrates how to decrypt MIME what was encrypted with RSAES-OAEP with SHA256 and AES-128 content encryption. In actuality, we don't really need to know in advance the various algorithms used to encrypt the MIME. When decrypting, the information about the algorithms required are embedded in the PCKS7 message itself, and this tells a decryptor what it should use. Note: This example requires Chilkat v9.5.0.67 or greater.
integer li_rc integer li_Success oleobject loo_Sb integer li_BCrlf oleobject loo_Mime oleobject loo_Cert oleobject loo_PrivKey oleobject loo_Mime2 // This requires the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. // We begin with this encrypted MIME: // Content-Type: application/x-pkcs7-mime; name="smime.p7m"; smime-type="enveloped-data" // someHeader1: Some value 1 // someHeader2: Some value 2 // Content-Disposition: attachment; filename="smime.p7m" // Content-Transfer-Encoding: base64 // // MIIDvAYJKoZIhvcNAQcDoIIDrTCCA6kCAQAxggGgMIIBnAIBADB1MGgxCzAJBgNVBAYTAlVTMQsw // CQYDVQQIDAJJTDEQMA4GA1UEBwwHV2hlYXRvbjEhMB8GA1UECgwYSW50ZXJuZXQgV2lkZ2l0cyBQ // dHkgTHRkMRcwFQYDVQQDDA5DaGlsa2F0V2lkZ2V0cwIJAMRwugDmvniwMBwGCSqGSIb3DQEBBzAP // oA0wCwYJYIZIAWUDBAIBBIIBAFaUL1ga1bOrdqYKcMm+FHUacBvzfBxk0fnPA0AMBdN8BvTWT3CN // YuqBhjOGyq0FpYD9pVZybUuFMCVsVyIW2O62HnsOK58YaPEUUcdH2sI+yjqX9UAn0P0nVDSsVdeK // W8x9kMfZg+3UP+y1q+lu7VRJO3f2C9oLQpTkc4VW4n7UOcUI0waykLCjCTL8lFDb7/J3GeuMKyhH // 5riNz50kpbzqn7m2Ks9yA+QmcTdXclclGFr2vwEUFzSdT2pxh/vaUrogCxkYWbQ2eV7vZg6O4kV0 // aqHBqySkPTAzHKiHH8K8GVdlTuJ8350CpICa4T8w7/Ht5I7dyOPPKy4C+rVtrvcwggH+BgkqhkiG // 9w0BBwEwHQYJYIZIAWUDBAECBBDTC2WNBN+z2I47/4Feu9YqgIIB0MZvl3nC/q/Wzil6HtfQTr12 // Q5moHY+ORzAa1P9XvX2ZUFhW530mV395mQw/A4o4ekmX9eRPEZquYzZPLT8hNeZIuNdhpcSQUmad // rKnKkR0wKJ3jJ3LhOIohVBQSYs8kVDZKq6lJBIznlsurFelZoNEhyRschhteDZx5rb7fCe8c2+/O // DHxaqaHCAzm/Bd7kcg6FFfuTZy3tu0PgP5IsXN4OFA3kkvwjAs4XsVS8jdIcmDNBkYieE8WmJOIm // Mz7mh/CHWLgWfGKa0Dkb9RcbFgLwYNT3GzuXFw9XPbKkEZjEAtJajWbN6P0WQl96YYd9qZxUpGxZ // zjTHEYzViUdUXolfpLufttrRXyxN1RFWhNFMFbv66xYqklMSgpdM/Mbk+EuvX6eXayDPvDBpfYMw // NoRAzv1Ony2c0ez9rBemJICicxAzpuvHbRxdjYs63Dnv+TYgpBK12AxWWpPIjXvw0WQKgTC3Tg8s // EnuGhpENqso/clJBEBSn4+2WhYtYbdI5sVme67lvqQl1Xxy3r18SWaQbyDOwgYi1E+54lMDOxMy0 // y0FPHk5pP45DnXWj+XORPp5LhuZr5mf62YOXSSUwR5P0cXy4Rc+pN5lhRQPCf5z2 loo_Sb = create oleobject // Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0 li_rc = loo_Sb.ConnectToNewObject("Chilkat.StringBuilder") if li_rc < 0 then destroy loo_Sb MessageBox("Error","Connecting to COM object failed") return end if li_BCrlf = 1 loo_Sb.AppendLine("Content-Type: application/x-pkcs7-mime; name=~"smime.p7m~"; smime-type=~"enveloped-data~"",li_BCrlf) loo_Sb.AppendLine("someHeader1: Some value 1",li_BCrlf) loo_Sb.AppendLine("someHeader2: Some value 2",li_BCrlf) loo_Sb.AppendLine("Content-Disposition: attachment; filename=~"smime.p7m~"",li_BCrlf) loo_Sb.AppendLine("Content-Transfer-Encoding: base64",li_BCrlf) loo_Sb.AppendLine("",li_BCrlf) loo_Sb.AppendLine("MIIDvAYJKoZIhvcNAQcDoIIDrTCCA6kCAQAxggGgMIIBnAIBADB1MGgxCzAJBgNVBAYTAlVTMQsw",li_BCrlf) loo_Sb.AppendLine("CQYDVQQIDAJJTDEQMA4GA1UEBwwHV2hlYXRvbjEhMB8GA1UECgwYSW50ZXJuZXQgV2lkZ2l0cyBQ",li_BCrlf) loo_Sb.AppendLine("dHkgTHRkMRcwFQYDVQQDDA5DaGlsa2F0V2lkZ2V0cwIJAMRwugDmvniwMBwGCSqGSIb3DQEBBzAP",li_BCrlf) loo_Sb.AppendLine("oA0wCwYJYIZIAWUDBAIBBIIBAFaUL1ga1bOrdqYKcMm+FHUacBvzfBxk0fnPA0AMBdN8BvTWT3CN",li_BCrlf) loo_Sb.AppendLine("YuqBhjOGyq0FpYD9pVZybUuFMCVsVyIW2O62HnsOK58YaPEUUcdH2sI+yjqX9UAn0P0nVDSsVdeK",li_BCrlf) loo_Sb.AppendLine("W8x9kMfZg+3UP+y1q+lu7VRJO3f2C9oLQpTkc4VW4n7UOcUI0waykLCjCTL8lFDb7/J3GeuMKyhH",li_BCrlf) loo_Sb.AppendLine("5riNz50kpbzqn7m2Ks9yA+QmcTdXclclGFr2vwEUFzSdT2pxh/vaUrogCxkYWbQ2eV7vZg6O4kV0",li_BCrlf) loo_Sb.AppendLine("aqHBqySkPTAzHKiHH8K8GVdlTuJ8350CpICa4T8w7/Ht5I7dyOPPKy4C+rVtrvcwggH+BgkqhkiG",li_BCrlf) loo_Sb.AppendLine("9w0BBwEwHQYJYIZIAWUDBAECBBDTC2WNBN+z2I47/4Feu9YqgIIB0MZvl3nC/q/Wzil6HtfQTr12",li_BCrlf) loo_Sb.AppendLine("Q5moHY+ORzAa1P9XvX2ZUFhW530mV395mQw/A4o4ekmX9eRPEZquYzZPLT8hNeZIuNdhpcSQUmad",li_BCrlf) loo_Sb.AppendLine("rKnKkR0wKJ3jJ3LhOIohVBQSYs8kVDZKq6lJBIznlsurFelZoNEhyRschhteDZx5rb7fCe8c2+/O",li_BCrlf) loo_Sb.AppendLine("DHxaqaHCAzm/Bd7kcg6FFfuTZy3tu0PgP5IsXN4OFA3kkvwjAs4XsVS8jdIcmDNBkYieE8WmJOIm",li_BCrlf) loo_Sb.AppendLine("Mz7mh/CHWLgWfGKa0Dkb9RcbFgLwYNT3GzuXFw9XPbKkEZjEAtJajWbN6P0WQl96YYd9qZxUpGxZ",li_BCrlf) loo_Sb.AppendLine("zjTHEYzViUdUXolfpLufttrRXyxN1RFWhNFMFbv66xYqklMSgpdM/Mbk+EuvX6eXayDPvDBpfYMw",li_BCrlf) loo_Sb.AppendLine("NoRAzv1Ony2c0ez9rBemJICicxAzpuvHbRxdjYs63Dnv+TYgpBK12AxWWpPIjXvw0WQKgTC3Tg8s",li_BCrlf) loo_Sb.AppendLine("EnuGhpENqso/clJBEBSn4+2WhYtYbdI5sVme67lvqQl1Xxy3r18SWaQbyDOwgYi1E+54lMDOxMy0",li_BCrlf) loo_Sb.AppendLine("y0FPHk5pP45DnXWj+XORPp5LhuZr5mf62YOXSSUwR5P0cXy4Rc+pN5lhRQPCf5z2",li_BCrlf) // Load the encrypted MIME into the MIME object. loo_Mime = create oleobject // Use "Chilkat_9_5_0.Mime" for versions of Chilkat < 10.0.0 li_rc = loo_Mime.ConnectToNewObject("Chilkat.Mime") loo_Mime.LoadMimeSb(loo_Sb) // Provide the required cert + private key from a PFX (.pfx/.p12) file. li_Success = loo_Mime.AddPfxSourceFile("qa_data/rsaes-oaep/cert_plus_privatekey.pfx","PFX_PASSWORD") if li_Success <> 1 then Write-Debug loo_Mime.LastErrorText destroy loo_Sb destroy loo_Mime return end if // Decrypt. li_Success = loo_Mime.Decrypt() if li_Success <> 1 then Write-Debug loo_Mime.LastErrorText destroy loo_Sb destroy loo_Mime return end if // Examine the decrypted MIME. Write-Debug loo_Mime.GetMime() Write-Debug "Decrypt test 1 succeeded." // ----------------------------------------------------------- // Now let's decrypt another way.. // We have the same cert and private key in PEM files.. loo_Cert = create oleobject // Use "Chilkat_9_5_0.Cert" for versions of Chilkat < 10.0.0 li_rc = loo_Cert.ConnectToNewObject("Chilkat.Cert") li_Success = loo_Cert.LoadFromFile("qa_data/rsaes-oaep/cert.pem") loo_PrivKey = create oleobject // Use "Chilkat_9_5_0.PrivateKey" for versions of Chilkat < 10.0.0 li_rc = loo_PrivKey.ConnectToNewObject("Chilkat.PrivateKey") li_Success = loo_PrivKey.LoadPemFile("qa_data/rsaes-oaep/privatekey.pem") // Decrypt using the cert + private key loo_Mime2 = create oleobject // Use "Chilkat_9_5_0.Mime" for versions of Chilkat < 10.0.0 li_rc = loo_Mime2.ConnectToNewObject("Chilkat.Mime") loo_Mime2.LoadMimeSb(loo_Sb) li_Success = loo_Mime2.Decrypt2(loo_Cert,loo_PrivKey) if li_Success <> 1 then Write-Debug loo_Mime2.LastErrorText destroy loo_Sb destroy loo_Mime destroy loo_Cert destroy loo_PrivKey destroy loo_Mime2 return end if // Examine the decrypted MIME. Write-Debug loo_Mime2.GetMime() Write-Debug "Decrypt test 2 succeeded." destroy loo_Sb destroy loo_Mime destroy loo_Cert destroy loo_PrivKey destroy loo_Mime2 |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.