I made a class to retrieve sensitive encrypted data from a file.
The class ClassSecret have a ReadOnly Property that return the sensitive data into a Dictionary.
The class DataProtector contains the function to decrypt the encrypted data.
I don't have much knowledge in computer science. I'm not sure if the variables values are stored somewhere in memory (and then can be accessed by unauthorized app) after I get the "Secrets" Property value from somewhere else in my program.
That's why I used a Try Finally to make the variables and objects egual to Nothing after the value of the property is returned.
I'm not using the Using statement since my class DataProtector don't have IDisposable implemented.
I may overcomplicate everything here. Is that Finally statement to make variables egual to Nothing is usefull, or all the variables are somewhat disposed automatically after the Get method returned the value as in the following code?
Thanks
The class ClassSecret have a ReadOnly Property that return the sensitive data into a Dictionary.
The class DataProtector contains the function to decrypt the encrypted data.
Code:
Imports System.Web.Script.Serialization
Public Class ClassSecret
Private Shared ReadOnly byteArray As Byte() = {0, 0} 'The sensitive data
Private Shared ReadOnly Property Secrets As Dictionary(Of String, String)
Get
Dim dp As DataProtector = Nothing
Dim tmpSecretsString As String
Dim tmpSecrets As Dictionary(Of String, String)
Dim serializer As JavaScriptSerializer = Nothing
Try
dp = New DataProtector
tmpSecretsString = dp.ProtectedDataToString(byteArray)
serializer = New JavaScriptSerializer()
tmpSecrets = serializer.Deserialize(Of Dictionary(Of String, String))(tmpSecretsString)
Return tmpSecrets
Finally
dp = Nothing
tmpSecretsString = Nothing
tmpSecrets = Nothing
serializer = Nothing
End Try
End Get
End Property
End Class
Public Class DataProtector
Public Function ProtectedDataToString(ByVal data As Byte()) As String
'Do some stuff
Dim newString As String = "{""decrypted"":""data""}"
Return newString
End Function
End Class
That's why I used a Try Finally to make the variables and objects egual to Nothing after the value of the property is returned.
I'm not using the Using statement since my class DataProtector don't have IDisposable implemented.
I may overcomplicate everything here. Is that Finally statement to make variables egual to Nothing is usefull, or all the variables are somewhat disposed automatically after the Get method returned the value as in the following code?
Code:
Private Shared ReadOnly Property Secrets As Dictionary(Of String, String)
Get
Dim tmpSecretsString As String = New DataProtector().ProtectedDataToString(byteArray)
Dim tmpSecrets As Dictionary(Of String, String) = New JavaScriptSerializer().Deserialize(Of Dictionary(Of String, String))(tmpSecretsString)
Return tmpSecrets
End Get
End Property