'Class module
' Requires Libraries:
' Encryption v1.10
' ByteConverter v1.10
'
Sub Class_Globals
End Sub
Public Sub Initialize
End Sub
#Region " Triple DES encryption code "
' sIV must be 8 bytes, sKEy must be 16 bytes, returns base-64 encoded encrypted string
Public Sub TripleDESEncrypt(sIV As String, sKey As String, dataToEncrypt As String) As String 'ignore
Dim kg As KeyGenerator
Dim C As Cipher
Dim B64 As Base64
Dim Bconv As ByteConverter
Dim data(0) As Byte
Dim iv(0) As Byte
If sIV.Length <> 8 OR sKey.Length <> 16 Then
Return Null
End If
iv = Bconv.StringToBytes(sIV, "ASCII")
C.Initialize("DESEDE/CBC/PKCS5Padding")
C.InitialisationVector = iv
kg.Initialize("DESEDE")
kg.KeyFromBytes(Bconv.StringToBytes(sKey, "ASCII"))
data = Bconv.StringToBytes(dataToEncrypt, "ASCII")
data = C.Encrypt(data, kg.Key, True)
Return B64.EncodeBtoS(data, 0, data.Length)
End Sub
' sIV must be 8 bytes, sKEy must be 16 bytes, returns plain-text decrypted string
Public Sub TripleDESDecrypt(sIV As String, sKey As String, Base64EncryptedData As String) As String 'ignore
Dim kg As KeyGenerator
Dim C As Cipher
Dim B64 As Base64
Dim Bconv As ByteConverter
Dim data(0) As Byte
Dim iv(0) As Byte
If sIV.Length <> 8 OR sKey.Length <> 16 Then
Return Null
End If
Try
iv = Bconv.StringToBytes(sIV, "ASCII")
C.Initialize("DESEDE/CBC/PKCS5Padding")
C.InitialisationVector = iv
kg.Initialize("DESEDE")
kg.KeyFromBytes(Bconv.StringToBytes(sKey, "ASCII"))
data = B64.DecodeStoB(Base64EncryptedData)
data = C.Decrypt(data, kg.Key, True)
Return Bconv.StringFromBytes(data, "ASCII")
Catch
LogColor("Error decrypting: " & LastException, Colors.Red)
End Try
Return ""
End Sub
#End Region