如何在 3des 中加密消息,使用模式 MODE_ECB ,192 长度密码,在 python

Howto encrypt a message in 3des, use mode MODE_ECB , 192 length password, in python

pip 安装 pycryptodome

from Crypto.Cipher import DES3

def encrypt_3ds(encrData):
    key = b"M4H5DE7mHXMS219b8adm9H4WFTElLfa26e7s3U7dBgT2hegt5fMq5aRfEv3345uiZh2zGxRPaBT663669mb01MCU9OHz2glYb2aOco5vJfoN9LKjxjOIZE64Jd4t9FUQ1F043TvRp4CwBX7Ug8Dp9fV25Zs4m7Z5DIL7H7D617jVcXLHT5Z83atR1sQcJpEG"
    aes = DES3.new(key, DES3.MODE_ECB)
    res = aes.encrypt(pad(encrData).encode('utf-8'))
    msg = str(base64.b64encode(res), encoding='utf8')
    return msg

引发 ValueError(“不是有效的 TDES 密钥”)

java 中的函数 class。我想加密 python.

中的消息
public class ThreeDES {
    private static final String IV = "1234567-";
    
    public static String encryptThreeDESECB(final String src, final String key) throws Exception {
        final DESedeKeySpec dks = new DESedeKeySpec(key.getBytes("UTF-8"));
        final SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DESede");
        final SecretKey securekey = keyFactory.generateSecret(dks);

        final Cipher cipher = Cipher.getInstance("DESede/ECB/PKCS5Padding");
        cipher.init(Cipher.ENCRYPT_MODE, securekey);
        final byte[] b = cipher.doFinal(src.getBytes());

        final BASE64Encoder encoder = new BASE64Encoder();
        return encoder.encode(b).replaceAll("\r", "").replaceAll("\n", "");

    }
}

3des encrypt key has 24 bytes.