简体   繁体   中英

Decrypt java (DESede/ECB/PKCS5Padding) cipher using python

Is it possible to implement like this technique in java (encryption and Decryption) using python?

Here the 3DES is using in this java code.

Cipher cipher = Cipher.getInstance("DESede/ECB/PKCS5Padding");
String keytext = "key......";
byte[] keyArray = keytext.getBytes("utf-8");
SecretKey key = new SecretKeySpec(keyArray, "DESede");

String mytext = "anytext......";
Cipher.init(1, key);
byte[] enc = cipher.doFinal(plaintext.getBytes("utf-8"));
String value = Base64.getUrlEncode().encodeToString(enc);
return value;

Hope someone can assist me with this, to implement this using python2 if possible or python3

EDIT:

from Crypto.Cipher import DES3
from Crypto.Random import get_random_bytes

while True:
  try:
    key = DES3.adjust_key_parity(get_random_bytes(24))
    break
  except ValueError:
    pass

cipher = DES3.new(key, DES3.MODE_CFB)
plaintext = b'We are no longer the knights who say ni!'
msg = cipher.iv + cipher.encrypt(plaintext)

print(msg)

Taken from the PyCryptodome manual itself: Link

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