Solved

DES / 3-des Encryption in VB

Posted on 2009-05-12
34
1,394 Views
Last Modified: 2013-11-15
I need code for encrypting an input byte array using  :
1. 8 byte key (array) via DES encryption algorithm
2. 16 byte key (array) via 3-DES encryption algorithm

And also, code to decrypt the same to yield the same inputs.
Instead of byte arrays, using the equivalent hex string is also ok.
code in vb/C# .NET is also ok



0
Comment
Question by:SwamyN
  • 22
  • 10
  • 2
34 Comments
 
LVL 46

Expert Comment

by:tbsgadi
ID: 24372190
0
 
LVL 19

Accepted Solution

by:
Rimvis earned 500 total points
ID: 24373133
Hello SwamyN,

Take a look here:
http://www.veign.com/code-view.php?type=app&codeid=76

Regards,

Rimvis
0
 

Author Comment

by:SwamyN
ID: 24373161
hey gary, out of the 3 links u provided, one requires me to download Chilkat, another encrypts files, and the third uses something called WindowsIdentity. If this is a class, can you please tell what i need to import to use this.
Thanks
0
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 
LVL 46

Expert Comment

by:tbsgadi
ID: 24373304
WindowsIdentity is a class
http://msdn.microsoft.com/en-us/library/system.security.principal.windowsidentity.aspx

I included the Microsoft link before, to give extra ideas
0
 

Author Comment

by:SwamyN
ID: 24373555
Hi Rimvis, I'm looking at the link you provided. It seems to be what i require in that it provides a means to encrypt and decrypt using DES and 3 DES.
However, it does not seem to match the sample data provided to me.
eg: input : 14229D2B084A895F20C2D30B5E800000
        key : A0A1A2A3A4A5A6A7
        blank initial vector
On DES encryption, this is supposed to yield
8A8D430D608714FE9E5052819C5A8D3C
while the program in the link returns PFSF7areUxmbx9dTAW4bzBiRE3TK3buuMncW0JcA1jHTg6mVtJaxHv4xU1YaJNXIdMWhP/qvvcdO
DH+/Fz5czKIKgKc=
 
0
 
LVL 19

Expert Comment

by:Rimvis
ID: 24373665
Which example are you referring to? PFSF7ar... represents data encoded in base64 string. Make sure that you are not confusing string data with hex string or with base64


0
 

Author Comment

by:SwamyN
ID: 24374321
@Rimvis :
The data that I am entering as input is a hex pair string. So is the key. (2 characters in the string represent a single byte).
The return value is in base 64 format. When i try to convert that to string format i get  '??????????????????????????????'
0
 
LVL 19

Expert Comment

by:Rimvis
ID: 24374528
BitConverter.ToString(Convert.FromBase64String("PFSF7areUxmbx9dTAW4bzBiRE3TK3buuMncW0JcA1jHTg6mVtJaxHv4xU1YaJNXIdMWhP/qvvcdODH+/Fz5czKIKgKc="))
returns bytes
"3C-54-85-ED-AA-DE-53-19-9B-C7-D7-53-01-6E-1B-CC-18-91-13-74-CA-DD-BB-AE-32-77-16-D0-97-00-D6-31-D3-83-A9-95-B4-96-B1-1E-FE-31-53-56-1A-24-D5-C8-74-C5-A1-3F-FA-AF-BD-C7-4E-0C-7F-BF-17-3E-5C-CC-A2-0A-80-A7"

So string should look something like this:
<T&7V}S:×Sn"ty{»®2w` Ö1Óƒ©"´±~1SV$Õ tÅü?[ƽN æ>\"¢
¤
I guess that you are converting it to Unicode.

Please post your code, it will make more sense.

0
 

Author Comment

by:SwamyN
ID: 24374607
@Gary,
Thanks, I used the WindowsIdentity class....but I'm still not getting the desired output. The text I am sending as string is a hex string. When it it being converted to a byte array just prior to being encrypted, using Encoding.Default.GetBytes (Hex_String), it isnt  converting it properly.
for example: '140A' gets converted to (49,52,00,65)     [an array of the ascii values of each character
when it should be converted to (14,10) [an array of each hex PAIR converted to byte]

Imports System.Security.Cryptography
Imports System.IO
Imports System.Text
Imports System.Security.Principal
 
 
Public Class Encryptor
 
 
 
    Private Shared des As TripleDESCryptoServiceProvider = _
      New TripleDESCryptoServiceProvider
 
    Private Shared ReadOnly Property Key() As Byte()
        Get
            Return Encoding.Default.GetBytes( _
              WindowsIdentity.GetCurrent.Name.PadRight(24, Chr(0)))
        End Get
    End Property
 
    Private Shared ReadOnly Property Vector() As Byte()
        Get
            Return Encoding.Default.GetBytes( _
              WindowsIdentity.GetCurrent().Name.PadRight(8, Chr(0)))
        End Get
    End Property
 
    Public Shared Function Encrypt(ByVal Text As String, ByVal EncryptKey As String) _
              As String
        'Return Transform(Text, des.CreateEncryptor(Key, Vector))
        Return Transform(Text, des.CreateEncryptor(Encoding.Default.GetBytes(EncryptKey), Encoding.Default.GetBytes(Convert.ToString("").PadRight(8, Chr(0)))))
    End Function
 
    Public Shared Function Decrypt( _
      ByVal encryptedText As String) As String
        Return Transform(encryptedText, _
               des.CreateDecryptor(Key, Vector))
    End Function
 
    Private Shared Function Transform(ByVal Text As String, _
      ByVal CryptoTransform As ICryptoTransform) As String
 
        Dim stream As MemoryStream = New MemoryStream
        Dim cryptoStream As CryptoStream = _
          New CryptoStream(stream, CryptoTransform, _
                              CryptoStreamMode.Write)
 
        Dim Input() As Byte = Encoding.Default.GetBytes(Text)
 
        cryptoStream.Write(Input, 0, Input.Length)
        cryptoStream.FlushFinalBlock()
 
        Return Encoding.Default.GetString(stream.ToArray())
    End Function
End Class

Open in new window

0
 

Author Comment

by:SwamyN
ID: 24374664
@Rimvis:
I'm using the same code in that zip file in the link u provided.
the folder 'EBCrypt Library' in VBCrypto_V2 folder. Do you want me to paste that Rimvis?
0
 

Author Comment

by:SwamyN
ID: 24374681
@Rimvis:
It uses ebCrypt.dll which has to be registered.
0
 

Author Comment

by:SwamyN
ID: 24374703
this is a sample input, key and output (all of which are hex strings)

eg: input : 14229D2B084A895F20C2D30B5E800000
       key : A0A1A2A3A4A5A6A7
       blank initial vector

On DES encryption, this is supposed to yield
8A8D430D608714FE9E5052819C5A8D3C
0
 
LVL 19

Expert Comment

by:Rimvis
ID: 24374747
I would like to see your code, which calls ebCrypt.dll
0
 

Author Comment

by:SwamyN
ID: 24374786
i'm attaching the main function which callsthat DLL
 

Public Function EncryptString(Which As Algorithms, Text As String, Optional OutputIn64 As Boolean, Optional Key As String, Optional Salt As String) As String
    On Error GoTo ErrorHandler
    Dim cipher As ebcryptlib.eb_c_Cipher
    Set cipher = New ebcryptlib.eb_c_Cipher
    If Len(Salt) < 8 Then Salt = Salt & Space$(8 - Len(Salt))
    If Which = BLOWFISH Then EncryptString = StrConv(cipher.EncryptString(EB_CRYPT_CIPHER_ALGORITHM_BLOWFISH_OFB, Key, Salt, Text), vbUnicode)
    If Which = CAST5 Then EncryptString = StrConv(cipher.EncryptString(EB_CRYPT_CIPHER_ALGORITHM_CAST5_OFB, Key, Salt, Text), vbUnicode)
    'If Which = DES Then EncryptString = StrConv(cipher.EncryptString(EB_CRYPT_CIPHER_ALGORITHM_DES_OFB, Key, Salt, Text), vbUnicode)
    If Which = DES Then EncryptString = cipher.EncryptString(EB_CRYPT_CIPHER_ALGORITHM_DES_OFB, Key, Salt, Text)
    If Which = DESE Then EncryptString = StrConv(cipher.EncryptString(EB_CRYPT_CIPHER_ALGORITHM_DESE_OFB, Key, Salt, Text), vbUnicode)
    If Which = TRIPLEDES Then EncryptString = StrConv(cipher.EncryptString(EB_CRYPT_CIPHER_ALGORITHM_DES3_OFB, Key, Salt, Text), vbUnicode)
    If Which = IDEA Then EncryptString = StrConv(cipher.EncryptString(EB_CRYPT_CIPHER_ALGORITHM_IDEA_OFB, Key, Salt, Text), vbUnicode)
    If Which = RC4 Then EncryptString = StrConv(cipher.EncryptString(EB_CRYPT_CIPHER_ALGORITHM_RC4, Key, Salt, Text), vbUnicode)
    If Which = RIJNDAEL128 Then EncryptString = StrConv(cipher.EncryptString(EB_CRYPT_CIPHER_ALGORITHM_RIJNDAEL_CBC_128, Key, Salt, Text), vbUnicode)
    If Which = RIJNDAEL192 Then EncryptString = StrConv(cipher.EncryptString(EB_CRYPT_CIPHER_ALGORITHM_RIJNDAEL_CBC_192, Key, Salt, Text), vbUnicode)
    If Which = RIJNDAEL256 Then EncryptString = StrConv(cipher.EncryptString(EB_CRYPT_CIPHER_ALGORITHM_RIJNDAEL_CBC_256, Key, Salt, Text), vbUnicode)
    If Which = SERPENT128 Then EncryptString = StrConv(cipher.EncryptString(EB_CRYPT_CIPHER_ALGORITHM_SERPENT_CBC_128, Key, Salt, Text), vbUnicode)
    If Which = SERPENT192 Then EncryptString = StrConv(cipher.EncryptString(EB_CRYPT_CIPHER_ALGORITHM_SERPENT_CBC_192, Key, Salt, Text), vbUnicode)
    If Which = SERPENT256 Then EncryptString = StrConv(cipher.EncryptString(EB_CRYPT_CIPHER_ALGORITHM_SERPENT_CBC_256, Key, Salt, Text), vbUnicode)
    If Which = TWOFISH Then EncryptString = StrConv(cipher.EncryptString(EB_CRYPT_CIPHER_ALGORITHM_TWOFISH_CBC, Key, Salt, Text), vbUnicode)
    If OutputIn64 = True Then EncryptString = Encode64(EncryptString)
    Key = "": Salt = "": Text = ""
    Exit Function
 
ErrorHandler:
MsgBox Err.Description
Key = "": Salt = "": Text = ""
End Function

Open in new window

0
 

Author Comment

by:SwamyN
ID: 24374845
i'm sending the above mentioned hex strings as 'Text' and 'Key' and '' as Salt. I assume that's the initial vector parameter. i tried removing the strconv to vbUniCode function, but as i mentioned, it returns ???????????????????????????????????. In the above function, i commented the original DES function, and pasted it below without converting it to a base64 string
0
 
LVL 19

Expert Comment

by:Rimvis
ID: 24374861
You can't use cipher.EncryptString to encrypt binary data. Use EncryptBLOBRaw instead.
0
 

Author Comment

by:SwamyN
ID: 24375050
I'm trying to use EncryptBLOBRaw, it's throwing an error at that statement saying
'IV Value is not of expected length. Expected 8 bytes.' .....i tried setting the variable 'Salt' to 8 spaces as well as 16 spaces.
0
 
LVL 19

Expert Comment

by:Rimvis
ID: 24382016
IV must be passed as hex string. Try 0000000000000000.
0
 

Author Comment

by:SwamyN
ID: 24382365
yeah that worked....to some extent...now i get another error : array expected as input parameter. I checked the function prototype. It requires a byte array as opposed to a hex string. I'm writing a function to convert hex string to byte array.  Does VB have any direct function to achieve this?
0
 
LVL 19

Expert Comment

by:Rimvis
ID: 24382423
No, there is no integrated function. You can use this:

Public Function HexStringToByteArray(sHex As String, ByRef narBytes() As Byte)
    Dim nLenInBytes As Integer
    Dim i As Integer
    
    If (Len(sHex) Mod 2 <> 0) Then
        Err.Raise 600, , "Invalid hex string: '" & sHex & "'"
    End If
    
    nLenInBytes = Len(sHex) / 2
    ReDim narBytes(nLenInBytes - 1)
    
    For i = 0 To nLenInBytes - 1
        narBytes(i) = HexStringToByte(Mid$(sHex, i * 2 + 1, 2))
    Next i
End Function

Open in new window

0
 

Author Comment

by:SwamyN
ID: 24382558
brilliant......thanks a mil....been looking for this for ages.....i managed to get the expected result on DES encryption.....i'll try a encrypt for 3-DES, and decrypt for both.
0
 

Author Comment

by:SwamyN
ID: 24382732
i tried to run a 3 DES encryption using the same conversion technique as above
However, the example i'm considering encrypts a 24 byte array using a 16 byte key
whn i try to simulate this, the dll returns an error saying the key needs to be 24 bytes. if i take the first 8 bytes of the 16 byte key and append it to the original 16 byte key, and use this 24 byte key to encrypt it, i get the expected result.
Is there any other work around?
0
 
LVL 19

Expert Comment

by:Rimvis
ID: 24382820
As I understand, 3DES key MUST be 24 bytes, as this algorithm uses 3 keys, 8 bytes each. I don't have access to ebCrypt.dll code, so I can't say for sure, how these 24 bytes are handled inside.

BTW, I'm not a encryption expert, but I think that if you use same bytes for K1 and K3, you are effectively using DES encryption, not 3DES.
0
 

Author Comment

by:SwamyN
ID: 24383040
right now, i'm using a 24 byte key comprising of the original key & the first 8 bytes (16 chars) of the key.. Using this, I can simulate the 3 DES encryption that i Have.
eg:
INPUT : 14229D2B084A895F20C2D30B5E8000009E5052819C5A8D3C
KEY : A0A1A2A3A4A5A6A7A8A9AAABACADAEAF
instead of the above key, i use :
A0A1A2A3A4A5A6A7A8A9AAABACADAEAFA0A1A2A3A4A5A6A7
and i get the desired result :
FD274CE840FA9AD139E4FC2923653A88743CB5986DB4F7A0
0
 

Author Comment

by:SwamyN
ID: 24383053
and i tried doing DES encryption with just first 8 bytes as key, the result i get is different, from the one i get when i use 3-DES with K1 = K3
0
 

Author Comment

by:SwamyN
ID: 24383070
Assuming K1 = K3 as a workaround, i can perform 3-DES encryption using this. But I'm facing a problem while decrypting this data.
It throws this error :
Could not encrypt/decrypt final block. Padding is not correct. Corrupted cipher text.
0
 

Author Comment

by:SwamyN
ID: 24383112
I've attached an image of the error. Even though the err.description just shows 'Could not encrypt/decrypt final block. Padding is not correct. Corrupted cipher text' . If i display the err.descritption as a msgbox. i get what's shown in the attached image.
untitled.JPG
0
 

Author Comment

by:SwamyN
ID: 24383134
the example i have for decryption is
encrypted hex string : A04B84A4DE515FD8A9D40DFFE703FBF1
Key : 4A895F20C2D30B5E9E5052819C5A8D3C
Key by appending first 8 bytes to make it 24 bytes:
4A895F20C2D30B5E9E5052819C5A8D3C4A895F20C2D30B5E
Expected String after 3-DES decryption:
EBDDE00C00800000E367401E2DA8FACB
0
 
LVL 19

Expert Comment

by:Rimvis
ID: 24383170
Are you using original EBCryptExample project? If not, can you please send me your version?
0
 

Author Comment

by:SwamyN
ID: 24383301
i've made minor modifications to 4 functions, and added 2 functions for hex_string to byte_array and vice cersa. SHould i attach the entire project? or just paste these 6 functions?
 
Attached below are 4 functions in modCipher
EncryptString
HexDump
StrToArray
DecryptString
 

Public Function EncryptString(Which As Algorithms, Text As String, Optional OutputIn64 As Boolean, Optional Key As String, Optional Salt As String) As String
    On Error GoTo ErrorHandler
    Dim cipher As ebcryptlib.eb_c_Cipher
    Set cipher = New ebcryptlib.eb_c_Cipher
    If Len(Salt) < 8 Then Salt = Salt & Space$(16 - Len(Salt))
    
    Dim ucSendData(64) As Byte
    Dim lSendDataLen As Long
    Dim ucReceivedData(64) As Byte
    Dim lReceivedDataLen As Long
    
    lSendDataLen = StrToArray(ucSendData, (Len(Text)) / 2, Text)
    
    
    If Which = BLOWFISH Then EncryptString = StrConv(cipher.EncryptString(EB_CRYPT_CIPHER_ALGORITHM_BLOWFISH_OFB, Key, Salt, Text), vbUnicode)
    If Which = CAST5 Then EncryptString = StrConv(cipher.EncryptString(EB_CRYPT_CIPHER_ALGORITHM_CAST5_OFB, Key, Salt, Text), vbUnicode)
    'If Which = DES Then EncryptString = StrConv(cipher.EncryptString(EB_CRYPT_CIPHER_ALGORITHM_DES_OFB, Key, Salt, Text), vbUnicode)
    If Which = DES Then EncryptString = HexDump(cipher.EncryptBLOBRaw(EB_CRYPT_CIPHER_ALGORITHM_DES_CBC, Key, Salt, ucSendData), (Len(Text)) / 2)
    If Which = DESE Then EncryptString = StrConv(cipher.EncryptString(EB_CRYPT_CIPHER_ALGORITHM_DESE_OFB, Key, Salt, Text), vbUnicode)
    'If Which = TRIPLEDES Then EncryptString = StrConv(cipher.EncryptString(EB_CRYPT_CIPHER_ALGORITHM_DES3_OFB, Key, Salt, Text), vbUnicode)
    If Which = TRIPLEDES Then EncryptString = HexDump(cipher.EncryptBLOBRaw(EB_CRYPT_CIPHER_ALGORITHM_DES3_CBC, Key, Salt, ucSendData), (Len(Text)) / 2)
    If Which = IDEA Then EncryptString = StrConv(cipher.EncryptString(EB_CRYPT_CIPHER_ALGORITHM_IDEA_OFB, Key, Salt, Text), vbUnicode)
    If Which = RC4 Then EncryptString = StrConv(cipher.EncryptString(EB_CRYPT_CIPHER_ALGORITHM_RC4, Key, Salt, Text), vbUnicode)
    If Which = RIJNDAEL128 Then EncryptString = StrConv(cipher.EncryptString(EB_CRYPT_CIPHER_ALGORITHM_RIJNDAEL_CBC_128, Key, Salt, Text), vbUnicode)
    If Which = RIJNDAEL192 Then EncryptString = StrConv(cipher.EncryptString(EB_CRYPT_CIPHER_ALGORITHM_RIJNDAEL_CBC_192, Key, Salt, Text), vbUnicode)
    If Which = RIJNDAEL256 Then EncryptString = StrConv(cipher.EncryptString(EB_CRYPT_CIPHER_ALGORITHM_RIJNDAEL_CBC_256, Key, Salt, Text), vbUnicode)
    If Which = SERPENT128 Then EncryptString = StrConv(cipher.EncryptString(EB_CRYPT_CIPHER_ALGORITHM_SERPENT_CBC_128, Key, Salt, Text), vbUnicode)
    If Which = SERPENT192 Then EncryptString = StrConv(cipher.EncryptString(EB_CRYPT_CIPHER_ALGORITHM_SERPENT_CBC_192, Key, Salt, Text), vbUnicode)
    If Which = SERPENT256 Then EncryptString = StrConv(cipher.EncryptString(EB_CRYPT_CIPHER_ALGORITHM_SERPENT_CBC_256, Key, Salt, Text), vbUnicode)
    If Which = TWOFISH Then EncryptString = StrConv(cipher.EncryptString(EB_CRYPT_CIPHER_ALGORITHM_TWOFISH_CBC, Key, Salt, Text), vbUnicode)
    
    
    
    If OutputIn64 = True Then EncryptString = Encode64(EncryptString)
    Key = "": Salt = "": Text = ""
    Exit Function
 
ErrorHandler:
MsgBox Err.Description
Key = "": Salt = "": Text = ""
End Function
 
'byte array to string
Public Function HexDump(response() As Byte, ByVal lenr As Long) As String
 
Dim OUT As String
Dim count As Integer
Dim value As Integer
Dim ifvalue As Integer
 
For count = 0 To lenr - 1 Step 1
    value = response(count)
   
    ifvalue = Fix(value / 16)
    If ifvalue > -1 And ifvalue < 10 Then
        OUT = OUT + String(1, ifvalue + 48)
    Else
        If ifvalue > 9 And ifvalue < 16 Then
            OUT = OUT + String(1, ifvalue + 55)
        End If
    End If
    
    value = Fix(value Mod 16)
        
    If value > -1 And value < 10 Then
        OUT = OUT + String(1, value + 48)
    Else
        If value > 9 And value < 16 Then
            OUT = OUT + String(1, value + 55)
        End If
    End If
     
    OUT = OUT + ""
Next count
 
HexDump = OUT
 
End Function
 
'string to byte array
Private Function StrToArray(ByRef ucBuffer() As Byte, ByVal BufferLen As Integer, ByVal str As String) As Integer
 
Dim i As Integer
Dim iStrLen As Integer
Dim iTmp As Integer
Dim sTmp As String
Dim temp(64) As Byte
iStrLen = Len(str)
 
If (iStrLen Mod 2) <> 0 Then
    MsgBox "Invalid String"
    Exit Function
End If
 
If BufferLen <> iStrLen / 2 Then
    MsgBox "Buffer size and string size does not match"
    Exit Function
End If
 
iTmp = 0
For i = 1 To iStrLen
    sTmp = Mid$(str, i, 1)
    iTmp = iTmp + Switch(sTmp = "A", 10, _
                         sTmp = "a", 10, _
                         sTmp = "B", 11, _
                         sTmp = "b", 11, _
                         sTmp = "C", 12, _
                         sTmp = "c", 12, _
                         sTmp = "D", 13, _
                         sTmp = "d", 13, _
                         sTmp = "E", 14, _
                         sTmp = "e", 14, _
                         sTmp = "F", 15, _
                         sTmp = "f", 15, _
                         1 = 1, sTmp _
                         )
  
    If (i Mod 2) = 0 Then
        temp((i / 2)) = iTmp
        iTmp = 0
    End If
    iTmp = iTmp * 16
Next
 
 
For i = 0 To BufferLen - 1 Step 1
    ucBuffer(i) = temp(i + 1)
Next
 
 
 
StrToArray = iStrLen / 2
 
 
End Function
 
 
 
Public Function DecryptString(Which As Algorithms, CipherText As String, Optional IsTextIn64 As Boolean, Optional Key As String, Optional Salt As String) As String
    On Error GoTo ErrorHandler
    Dim cipher As ebcryptlib.eb_c_Cipher, BArray() As Byte
    Set cipher = New ebcryptlib.eb_c_Cipher
    If IsTextIn64 = True Then CipherText = Decode64(CipherText)
    If Len(Salt) < 8 Then Salt = Salt & Space$(8 - Len(Salt))
    BArray() = StrConv(CipherText, vbFromUnicode)
    
    Dim ucSendData(64) As Byte
    Dim lSendDataLen As Long
    lSendDataLen = StrToArray(BArray, (Len(CipherText)) / 2, CipherText)
    
    If Which = BLOWFISH Then DecryptString = cipher.DecryptString(EB_CRYPT_CIPHER_ALGORITHM_BLOWFISH_OFB, Key, Salt, BArray())
    If Which = CAST5 Then DecryptString = cipher.DecryptString(EB_CRYPT_CIPHER_ALGORITHM_CAST5_OFB, Key, Salt, BArray())
    'If Which = DES Then DecryptString = cipher.DecryptString(EB_CRYPT_CIPHER_ALGORITHM_DES_OFB, Key, Salt, BArray())
    If Which = DES Then DecryptString = cipher.DecryptBLOBRaw(EB_CRYPT_CIPHER_ALGORITHM_DES_CBC, Key, Salt, BArray())
    If Which = DESE Then DecryptString = cipher.DecryptString(EB_CRYPT_CIPHER_ALGORITHM_DESE_OFB, Key, Salt, BArray())
    If Which = IDEA Then DecryptString = cipher.DecryptString(EB_CRYPT_CIPHER_ALGORITHM_IDEA_OFB, Key, Salt, BArray())
    'If Which = TRIPLEDES Then DecryptString = cipher.DecryptString(EB_CRYPT_CIPHER_ALGORITHM_DES3_OFB, Key, Salt, BArray())
    If Which = TRIPLEDES Then DecryptString = cipher.DecryptBLOBRaw(EB_CRYPT_CIPHER_ALGORITHM_DES3_CBC, Key, Salt, BArray)
    If Which = TWOFISH Then DecryptString = cipher.DecryptString(EB_CRYPT_CIPHER_ALGORITHM_TWOFISH_CBC, Key, Salt, BArray())
    If Which = RC4 Then DecryptString = cipher.DecryptString(EB_CRYPT_CIPHER_ALGORITHM_RC4, Key, Salt, BArray())
    If Which = RIJNDAEL128 Then DecryptString = cipher.DecryptString(EB_CRYPT_CIPHER_ALGORITHM_RIJNDAEL_CBC_128, Key, Salt, BArray())
    If Which = RIJNDAEL192 Then DecryptString = cipher.DecryptString(EB_CRYPT_CIPHER_ALGORITHM_RIJNDAEL_CBC_192, Key, Salt, BArray())
    If Which = RIJNDAEL256 Then DecryptString = cipher.DecryptString(EB_CRYPT_CIPHER_ALGORITHM_RIJNDAEL_CBC_256, Key, Salt, BArray())
    If Which = SERPENT128 Then DecryptString = cipher.DecryptString(EB_CRYPT_CIPHER_ALGORITHM_SERPENT_CBC_128, Key, Salt, BArray())
    If Which = SERPENT192 Then DecryptString = cipher.DecryptString(EB_CRYPT_CIPHER_ALGORITHM_SERPENT_CBC_192, Key, Salt, BArray())
    If Which = SERPENT256 Then DecryptString = cipher.DecryptString(EB_CRYPT_CIPHER_ALGORITHM_SERPENT_CBC_256, Key, Salt, BArray())
    
    Key = "": Salt = "": CipherText = ""
    Exit Function
    
ErrorHandler:
MsgBox Err.Description
Key = "": Salt = "": CipherText = ""
End Function

Open in new window

0
 

Author Comment

by:SwamyN
ID: 24383315
and attached below are the changes made to frmCiphers
 The only thing changes here is one of the parameters sent as false instead of true indicating that the input is not in base64 format
 

Private Sub Label1_Click()
    txtOutput.Text = EncryptString(cmbAlgorithms.ListIndex, txtText, False, txtKeyE, txtSaltE)
End Sub
 
Private Sub Label13_Click()
    txtText2.Text = DecryptString(cmbAlgorithms.ListIndex, txtOutput, False, txtKeyD, txtSaltD)
End Sub 

Open in new window

0
 
LVL 19

Expert Comment

by:Rimvis
ID: 24383552
Sorry, I don't know how to solve this. Have you tried DecryptBLOB?
0
 

Author Comment

by:SwamyN
ID: 24383705
ok....i'll try that.....thanks for all ur help rimvis.... :-)
0
 

Author Comment

by:SwamyN
ID: 24383714
if you get any other ideas, do let me know....thanks
0

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When the confidentiality and security of your data is a must, trust the highly encrypted cloud fax portfolio used by 12 million businesses worldwide, including nearly half of the Fortune 500.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question