Search The ForumSearch   RegisterRegister  LoginLogin

MailBee.NET Objects

 AfterLogic Forum : MailBee.NET Objects
Subject Topic: Smime Post ReplyPost New Topic
Author
Message << Prev Topic | Next Topic >>
adam.kozovo
Newbie
Newbie


Joined: 30 June 2023
Online Status: Offline
Posts: 19
Posted: 12 July 2023 at 9:56pm | IP Logged Quote adam.kozovo

Hello. do you like to make SmimeResult and MsgConvert Classes disposable to dispose message and certificates from SmimeResult afterwards when used with USING? Such classes which contains sensitive info such as certificates shall be disposable, am I correct?


And after loading an email to EmailMessage , may I always use this code for all kind of messages? (both encrypted and non-encrypted messages)


Dim SmimeResult1 As SmimeResult = Smime1.DecryptAndVerify(EmailMessage1, MessageVerificationFlags.All, Nothing, Nothing)

If SmimeResult1 IsNot Nothing AndAlso SmimeResult1.DecryptedMessage IsNot Nothing Then EmailMessage = SmimeResult1.DecryptedMessage

SmimeResult1.DecryptedMessage.Dispose()
SmimeResult1 = Nothing
Back to Top View adam.kozovo's Profile Search for other posts by adam.kozovo
 
Alex
AfterLogic Support
AfterLogic Support
Avatar

Joined: 19 November 2003
Online Status: Offline
Posts: 2206
Posted: 13 July 2023 at 2:42am | IP Logged Quote Alex

Hello,

MsgConvert does not deal with unmanaged resources.

Neither SmimeResult does. Although you can see Dispose in Certificate class the truth is that it remains for backward compatibility only. It does nothing. The original version of MailBee.NET Objects relied on Win32 implementation of certificates and thus indeed used unmanaged resource. However, since .NET 2.0 which added .NET's native support of certificates, this has been rewritten to re-use the managed APIs only.

Regards,
Alex
Back to Top View Alex's Profile Search for other posts by Alex
 
adam.kozovo
Newbie
Newbie


Joined: 30 June 2023
Online Status: Offline
Posts: 19
Posted: 14 July 2023 at 11:10pm | IP Logged Quote adam.kozovo

Hello
Thanks for your detailed response, you're right as Dispose was added since .net framework 4.6
https://learn.microsoft.com/en-us/dotnet/api/system.security.cryptography.x509certificates.x509certificate.dispose?view=netframework-4.6

Still makes sense to have a disposable class and manually clear certificate collections and set certificates to nothing:
https://snede.net/the-most-dangerous-constructor-in-net/
Back to Top View adam.kozovo's Profile Search for other posts by adam.kozovo
 
adam.kozovo
Newbie
Newbie


Joined: 30 June 2023
Online Status: Offline
Posts: 19
Posted: 14 July 2023 at 11:15pm | IP Logged Quote adam.kozovo

Sorry forgot to add: after loading an email to EmailMessage , may I always use this code for all kind of messages? (both encrypted and non-encrypted messages)
If I just need the decrypted messages without any certificate info:


Dim SmimeResult1 As SmimeResult = Smime1.DecryptAndVerify(EmailMessage1, MessageVerificationFlags.All, Nothing, Nothing)

If SmimeResult1 IsNot Nothing AndAlso SmimeResult1.DecryptedMessage IsNot Nothing Then EmailMessage = SmimeResult1.DecryptedMessage

SmimeResult1.DecryptedMessage.Dispose()
SmimeResult1 = Nothing
Back to Top View adam.kozovo's Profile Search for other posts by adam.kozovo
 
Alex
AfterLogic Support
AfterLogic Support
Avatar

Joined: 19 November 2003
Online Status: Offline
Posts: 2206
Posted: 18 July 2023 at 3:51am | IP Logged Quote Alex

Hi,

You're confusing X509Certificate with X509Certificate2. MailBee.NET does not deal with X509Certificate class, only with X509Certificate2 which does not support (neither does it need) Dispose.

As for DecryptAndVerify, mostly yes but I'd recommend DecryptAndVerify2 instead of DecryptAndVerify as it's .NET Standard 2.0 compliant and does not rely on Win32 API.

Regards,
Alex
Back to Top View Alex's Profile Search for other posts by Alex
 

If you wish to post a reply to this topic you must first login
If you are not already registered you must first register

  Post ReplyPost New Topic
Printable version Printable version

Forum Jump

Powered by Web Wiz Forums version 7.9
Copyright ©2001-2004 Web Wiz Guide