T
T
The-TS2020-09-17 21:15:28
PHP
The-TS, 2020-09-17 21:15:28

How can I Encrypt/Decrypt DES?

Here is the encryption in Python(3):
from Crypto.Cipher import DES

key = b'abcdefgh'

def pad(text):
    while len(text) % 8 != 0:
        text += b' '
    return text

des = DES.new(key, DES.MODE_ECB)
text = b'Python rocks!'
padded_text = pad(text)

encrypted_text = des.encrypt(padded_text)
print(encrypted_text)
# b'>\xfc\x1f\x16x\x87\xb2\x93\x0e\xfcH\x02\xd59VQ'

How can I decrypt this in PHP and how can I also encrypt?
Thanks

Answer the question

In order to leave comments, you need to log in

2 answer(s)
O
Ocelot, 2020-09-17
@Ocelot

https://www.php.net/manual/en/book.mcrypt.php

N
nokimaro, 2020-09-18
@nokimaro

https://github.com/stymiee/php-simple-encryption
Uses Openssl extension and can be in des
python code needs cipher=des-ecb

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question