Visual Studio

While creating desktop applications many times you need to save some application data in the registry. This removes application dependency on the files for configuration or one-off information. This code does not need any additional library to be added and the developer can create their own path for storing key-value pairs.

Share this:

Like this:

For a long period of time, I was using my own code encryption techniques as part of login validations for the standalone desktop applications. But recently I was looking for high level of encryption for storing login information. This can also be used to create licence keys. Below code provided two-way encryption.It needs the private key string as the wrapper to generate unique decrypted string.

‘Wrapper text is similer to the private key which can be any random string Dim wrapper As New Simple3Des(“dusyifdsuy2787%45^hffhj%$*kfhk*gGF4982798^^^879hfsjsbdkjfdkjjfdklmbmbmvefhkhwhelh“) ‘Dim cipherText As String = wrapper.EncryptData(nics(0).GetPhysicalAddress.ToString) Dim strInputText As String strInputText = “” For i = 1 To 10 strInputText = strInputText & Trim(txtInputKey.Text) Next i txtEncryptedValue.Text = wrapper.EncryptData(strInputText) Else MsgBox(“No Information To Encrypt”, MsgBoxStyle.Critical, “License Maker”) End If End Sub

‘ Create the stream. Dim ms As New System.IO.MemoryStream ‘ Create the encoder to write to the stream. Dim encStream As New CryptoStream(ms, TripleDes.CreateEncryptor(), System.Security.Cryptography.CryptoStreamMode.Write)

‘ Use the crypto stream to write the byte array to the stream. encStream.Write(plaintextBytes, 0, plaintextBytes.Length) encStream.FlushFinalBlock()

‘ Convert the encrypted stream to a printable string. Return Convert.ToBase64String(ms.ToArray) End Function

‘ Create the stream. Dim ms As New System.IO.MemoryStream ‘ Create the decoder to write to the stream. Dim decStream As New CryptoStream(ms, TripleDes.CreateDecryptor(), System.Security.Cryptography.CryptoStreamMode.Write)

‘ Use the crypto stream to write the byte array to the stream. decStream.Write(encryptedBytes, 0, encryptedBytes.Length) decStream.FlushFinalBlock()

‘ Convert the plaintext stream to a string. Return System.Text.Encoding.Unicode.GetString(ms.ToArray) End FunctionEnd Class