Skip to content

Instantly share code, notes, and snippets.

@Laicure
Last active October 12, 2016 22:36
Show Gist options
  • Save Laicure/b70c37b844b18643c791 to your computer and use it in GitHub Desktop.
Save Laicure/b70c37b844b18643c791 to your computer and use it in GitHub Desktop.
[vb] RijndaelManaged Snippet
Imports System.Security.Cryptography
Imports System.Text
Module Encryptor
'********** Cryptography Declarations
Private cipherX As New RijndaelManaged
'Keys can be 1~255, separated by a comma
'keyBytes have 32 non-duplicating values
Private keyBytes As Byte() = {}
'IVBytes have 16 non-duplicating values
Private IVBytes As Byte() = {}
#Region "Encryptor"
Friend Function EncryptX(ByVal ToEncrypt As String) As String
Dim enC As ICryptoTransform = cipherX.CreateEncryptor(keyBytes, IVBytes)
Dim dataByte As Byte() = Encoding.Unicode.GetBytes(ToEncrypt)
Return Convert.ToBase64String(enC.TransformFinalBlock(dataByte, 0, dataByte.Length))
End Function
#End Region
#Region "Decryptor"
Friend Function DecryptX(ByVal ToDecrypt As String) As String
Dim DenC As ICryptoTransform = cipherX.CreateDecryptor(keyBytes, IVBytes)
Dim dataByte As Byte() = Convert.FromBase64String(ToDecrypt)
Return Encoding.Unicode.GetString(DenC.TransformFinalBlock(dataByte, 0, dataByte.Length))
End Function
#End Region
End Module
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment