Click here to Skip to main content
15,037,928 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Please refer to this website 3DES Encryption – Easily encrypt or decrypt strings or files[^]

Text: Text/Hex =Function: 3DES/CBC/Key:HEX
KEY:3E4F5612EF64305955D543B0AE3508807968905960C44D37
IV: 8049e91025a6b548
INPUT:
7F79C6CAEB9DD463D80ADFC07D4D255195DA546D953FEF9C66AAD359BF925CADA93BD861633099D0


DATA OUPUT SHOUL BE:
63585268636B5A534E46673675564959556F31697A754568544A497A7955796E6B773D3D00000000

However, the codes that I'm using, im receiving error.
Specified block size is not valid for this algorithm.
Any one have a better idea.

What I have tried:

============== FIRST CODE ===========
Private TRIPLE3DES As New TripleDESCryptoServiceProvider
    Public Function DECRYPTDATA(ByVal ENCRYPTED_DATA As String) As String
        TRIPLE3DES.KeySize = 128
        TRIPLE3DES.BlockSize = 128
        TRIPLE3DES.Padding = PaddingMode.Zeros
        TRIPLE3DES.Key = DES_3Key
        TRIPLE3DES.IV = DES_IVector
        
        Dim ENCRYPTEBYTES() As Byte = Convert.FromBase64String(ENCRYPTED_DATA)
        Dim MS As New System.IO.MemoryStream

        Dim DECSTREAM As New CryptoStream(MS, TRIPLE3DES.CreateDecryptor(), System.Security.Cryptography.CryptoStreamMode.Write)
        DECSTREAM.Write(ENCRYPTEBYTES, 0, ENCRYPTEBYTES.Length)
        DECSTREAM.FlushFinalBlock()
        Return System.Text.Encoding.Unicode.GetString(MS.ToArray)
    End Function


============== SECOND CODE ===========

Public Function Decrypt_(ByVal data As Byte(), ByVal key As Byte(), ByVal iv As Byte()) As Byte()
       Using DES3_CBC = Aes.Create()
           DES3_CBC.KeySize = 128
           DES3_CBC.BlockSize = 128
           DES3_CBC.Padding = PaddingMode.Zeros
           DES3_CBC.Key = key
           DES3_CBC.IV = iv

           Using decryptor = DES3_ECB.CreateDecryptor(DES3_CBC.Key, DES3_CBC.IV)
               Return PerformCryptography(data, decryptor)
           End Using
       End Using
   End Function

   Private Function PerformCryptography(ByVal data As Byte(), ByVal cryptoTransform As ICryptoTransform) As Byte()
       Using ms = New MemoryStream()

           Using cryptoStream = New CryptoStream(ms, cryptoTransform, CryptoStreamMode.Write)
               cryptoStream.Write(data, 0, data.Length)
               cryptoStream.FlushFinalBlock()
               Return ms.ToArray()
           End Using
       End Using
   End Function
Posted
Updated 12-Mar-21 21:54pm
v5
Comments
Patrice T 9-Mar-21 21:24pm
   
Apply the secret solution matching the secret error.
Patrice T 9-Mar-21 22:03pm
   
And you okan to tell the error message ?
Use Improve question to update your question.
Patrice T 9-Mar-21 22:25pm
   
Use Improve question to update your question.
CPallini 10-Mar-21 2:09am
   
:-D

1 solution

Why are you using a website that does not work, rather than the actual documentation, which contains a working example? See TripleDESCryptoServiceProvider Class (System.Security.Cryptography) | Microsoft Docs[^].
   
Comments
CPallini 10-Mar-21 4:56am
   
5.
Nicky Ralph 13-Mar-21 15:48pm
   
I've tried the link above, however i cant decrypt data without getting from encrypted string.
Richard MacCutchan 14-Mar-21 4:16am
   
Sorry, but what does that mean?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900