0

I Import the Imports System.Security.Cryptography to encrypt my password but using this and adding this code.

Public Function EncryptData(ByVal plaintext As String) As String
    Dim plainttextBytes() As Byte = System.Text.Encoding.Unicode.GetBytes(plaintext)
    Dim ms As New System.IO.MemoryStream
    Dim encStream As New CryptoStream(ms, TripleDES.CreateEncryptor(), System.Security.Cryptography.CryptoStreamMode.Write)

    encStream.Write(plainttextBytes, 0, plainttextBytes.Length)
    encStream.FlushFinalBlock()

    Return Convert.ToBase64String(ms.ToArray)

End Function

I'm having a error Reference to a non-shared member requires an object reference. Can someone help me. Thanks

Gerry
  • 73
  • 6
  • Does this answer your question? [Reference to a non-shared member requires an object reference occurs when calling public sub](https://stackoverflow.com/questions/13462479/reference-to-a-non-shared-member-requires-an-object-reference-occurs-when-callin) – derpirscher Feb 20 '23 at 06:49

1 Answers1

1

CreateEncryptor is an instance method, not Shared, so you need to call it on an instance of the TripleDES class, not on the class itself. What you're doing would be akin to this:

Return Convert.ToBase64String(MemoryStream.ToArray)

You are obviously calling ToArray on an instance of the MemoryStream class rather than on the class itself. You need to do the same for the TripleDES.CreateEncryptor method, i.e. create an instance of the class first and then call the method on that.

jmcilhinney
  • 50,448
  • 5
  • 26
  • 46