here:
CryptoJS.enc.Base64.parse('3DJ3XmbByr2y6w1113159151954972672')
CryptoJS.enc.Base64.parse('3DJ3XmbByr2y6w1113159151954972672').toString()
CryptoJS.enc.Base64.parse('3DJ3XmbByr2y6w1113159151954972672').toString(CryptoJS.enc.Base64)
CryptoJS.enc.Base64.parse('3DJ3XmbByr2y6w111315915195497267')
CryptoJS.enc.Base64.parse('3DJ3XmbByr2y6w111315915195497267').toString()
CryptoJS.enc.Base64.parse('3DJ3XmbByr2y6w111315915195497267').toString(CryptoJS.enc.Base64)
the return is the same 24 byte length object WordArray but the input is different length .
why?
function encryptByTripleDES(msg, key) {
const keyHex = CryptoJS.enc.Base64.parse(key)
const encrypted = CryptoJS.TripleDES.encrypt(msg, keyHex, {
mode: CryptoJS.mode.ECB,
padding: CryptoJS.pad.Pkcs7
})
return encrypted.toString()
}
here is the 3des achive of cryptojs. when the length of inputted key is 33 like '3DJ3XmbByr2y6w1113159151954972672', it works. when i use this key to do 3des encrypt in python,it will doesn't work( the key length is wrong) how to implements in python?
def encrypt_by_triple_des(data:str, key):
key_bytes = base64.b64decode(key)
msg_bytes = data.encode('utf-8')
cipher = DES3.new(key_bytes, DES3.MODE_ECB)
padded_msg = pad(msg_bytes, DES3.block_size)
encrypted_msg = cipher.encrypt(padded_msg)
return base64.b64encode(encrypted_msg).decode('utf-8')
if the length of key satisfied 32,it works . in this case, some key can work in cryptojs but not in python.