You may want to encrypt end user license files or any other data within your application. TLL brings a integrated features to do such task easily. You can use this example simply by copying into new class in your project and calling it’s easily understandable functions. Don’t forget to change initialization vector, salt and iteration count on per application basis.

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using TreeksLicensingLibrary;
  6.  
  7. namespace LicenseLibraryExample
  8. {
  9.     class Encryption
  10.     {
  11.         //IV must be 16 chars long
  12.         protected string myInitializationVector = "CHANGE_TO_YOURS1";
  13.         //salt can be string of any lenght
  14.         protected string mySalt = "YOUR_SALT_FORENCRYPTION_OF_ANY_LENGHT";
  15.         //iterations is number of encryption cycles, the more is secure and also slower
  16.         protected int myIterations = 20000;
  17.  
  18.         public string EncryptText(string strPlain, string strPassword)
  19.         {
  20.             try
  21.             {
  22.                 string strEncrypted = Rijndael256.EncryptString256Bit(strPlain, strPassword, mySalt, 256, myIterations, myInitializationVector);
  23.  
  24.                 return strEncrypted;
  25.             }
  26.             catch (Exception ex)
  27.             {
  28.                 return ex.Message;
  29.             }
  30.  
  31.         }
  32.  
  33.         public string DecryptText(string strEncrypted, string strPassword)
  34.         {
  35.             try
  36.             {
  37.                 string strDecrypted = Rijndael256.DecryptString256Bit(strEncrypted, strPassword, mySalt, 256, myIterations, myInitializationVector);
  38.  
  39.                 return strDecrypted;
  40.             }
  41.             catch (Exception ex)
  42.             {
  43.                 return ex.Message;
  44.             }
  45.  
  46.         }
  47.  
  48.         public string EncryptFile(string strPlainPath, string strResultPath, string strPassword)
  49.         {
  50.             try
  51.             {
  52.                 byte[] bytPlain = System.IO.File.ReadAllBytes(strPlainPath);
  53.                 byte[] bytEncrypted = (byte[])Rijndael256.EncryptBytes256Bit(bytPlain, strPassword, mySalt, 256, myIterations, myInitializationVector, "SHA1", false);
  54.  
  55.                 System.IO.File.WriteAllBytes(strResultPath, bytEncrypted);
  56.  
  57.                 return "OK";
  58.             }
  59.             catch (Exception ex)
  60.             {
  61.                 return ex.Message;
  62.             }
  63.         }
  64.  
  65.         public string DecryptFile(string strEncryptedPath, string strResultPath, string strPassword)
  66.         {
  67.             try
  68.             {
  69.                 byte[] bytEncrypted = System.IO.File.ReadAllBytes(strEncryptedPath);
  70.                 byte[] bytDecrypted = Rijndael256.DecryptBytes256Bit(bytEncrypted, strPassword, mySalt, 256, myIterations, myInitializationVector, "SHA1");
  71.  
  72.                 System.IO.File.WriteAllBytes(strResultPath, bytDecrypted);
  73.  
  74.                 return "OK";
  75.             }
  76.             catch (Exception ex)
  77.             {
  78.                 return ex.Message;
  79.             }
  80.         }
  81.  
  82.     }
  83. }
  1. Imports System.Collections.Generic
  2. Imports System.Linq
  3. Imports System.Text
  4. Imports TreeksLicensingLibrary
  5.  
  6. Namespace LicenseLibraryExample
  7.     Class Encryption
  8.         'IV must be 16 chars long
  9.        Protected myInitializationVector As String = "CHANGE_TO_YOURS1"
  10.         'salt can be string of any lenght
  11.        Protected mySalt As String = "YOUR_SALT_FORENCRYPTION_OF_ANY_LENGHT"
  12.         'iterations is number of encryption cycles, the more is secure and also slower
  13.        Protected myIterations As Integer = 20000
  14.  
  15.         Public Function EncryptText(strPlain As String, strPassword As String) As String
  16.             Try
  17.                 Dim strEncrypted As String = Rijndael256.EncryptString256Bit(strPlain, strPassword, mySalt, 256, myIterations, myInitializationVector)
  18.  
  19.                 Return strEncrypted
  20.             Catch ex As Exception
  21.                 Return ex.Message
  22.             End Try
  23.  
  24.         End Function
  25.  
  26.         Public Function DecryptText(strEncrypted As String, strPassword As String) As String
  27.             Try
  28.                 Dim strDecrypted As String = Rijndael256.DecryptString256Bit(strEncrypted, strPassword, mySalt, 256, myIterations, myInitializationVector)
  29.  
  30.                 Return strDecrypted
  31.             Catch ex As Exception
  32.                 Return ex.Message
  33.             End Try
  34.  
  35.         End Function
  36.  
  37.         Public Function EncryptFile(strPlainPath As String, strResultPath As String, strPassword As String) As String
  38.             Try
  39.                 Dim bytPlain As Byte() = System.IO.File.ReadAllBytes(strPlainPath)
  40.                 Dim bytEncrypted As Byte() = DirectCast(Rijndael256.EncryptBytes256Bit(bytPlain, strPassword, mySalt, 256, myIterations, myInitializationVector, _
  41.                  "SHA1", False), Byte())
  42.  
  43.                 System.IO.File.WriteAllBytes(strResultPath, bytEncrypted)
  44.  
  45.                 Return "OK"
  46.             Catch ex As Exception
  47.                 Return ex.Message
  48.             End Try
  49.         End Function
  50.  
  51.         Public Function DecryptFile(strEncryptedPath As String, strResultPath As String, strPassword As String) As String
  52.             Try
  53.                 Dim bytEncrypted As Byte() = System.IO.File.ReadAllBytes(strEncryptedPath)
  54.                 Dim bytDecrypted As Byte() = Rijndael256.DecryptBytes256Bit(bytEncrypted, strPassword, mySalt, 256, myIterations, myInitializationVector, _
  55.                  "SHA1")
  56.  
  57.                 System.IO.File.WriteAllBytes(strResultPath, bytDecrypted)
  58.  
  59.                 Return "OK"
  60.             Catch ex As Exception
  61.                 Return ex.Message
  62.             End Try
  63.         End Function
  64.  
  65.     End Class
  66. End Namespace