简体   繁体   中英

Python TripleDES decryption

I'm trying to decrypt a string in python encrypted using 3DES. It is encrypted by VB.net by my formal mate. I have no idea what is going on. The partial code in VB.net is

Private key() As Byte = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24}
Private iv() As Byte = {65, 110, 68, 26, 69, 178, 200, 219}
Private objTripleDES As New clsTripleDES(key, iv)

The code is similar is to https://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=1564&lngWId=10

Is it possible to decrypt in python? Do I need to use bytearray?

How about something like this:

from Crypto.Cipher import DES3

key = [
     1,  2,  3,  4,  5,  6,  7,  8, 
     9, 10, 11, 12, 13, 14, 15, 16, 
     17, 18, 19, 20, 21, 22, 23, 24
]

iv = [65, 110, 68, 26, 69, 178, 200, 219]

keyStr = ""
ivStr = ""

for i in key: 
    keyStr += chr(i)

for i in iv: 
    ivStr += chr(i)

encr = DES3.new(keyStr, DES3.MODE_CBC, ivStr)
decr = DES3.new(keyStr, DES3.MODE_CBC, ivStr)

#Outputs "1234567891234567"
print decr.decrypt(encr.encrypt("1234567891234567"))

You should investigate what mode was used for encryption in VB code. CBC is the default mode, according to this , but you can't be sure. See this when you figure out what mode was used.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM