Keine Salt-AES-Verschlüsselung in Python

Wenn Sie die folgende AES-256-CBC-Verschlüsselung mit openssl mit der Option '-nosalt' in Python realisieren möchten.

echo "this is secret"|openssl enc -aes-256-cbc -e -base64 -pass pass:hogehoge -p -nosalt

Es wurde so gemacht.

def encryptAes(str, encKey, key_length=32, iv_length=16):
    d = d_i = ''
    while len(d) < key_length + iv_length:
        d_i = md5(d_i + encKey).digest()
        d += d_i
    key = d[:key_length]
    iv = d[key_length:key_length+iv_length]
    cipher = AES.new(key, AES.MODE_CBC, iv)
    _str = str + (iv_length - len(str) % iv_length) * chr(iv_length - len(str) % iv_length)
    return base64.b16encode(cipher.encrypt(_str)).lower()
print encyptAes("this is secret","hogehoge")

Als Memorandum verlassen.

Recommended Posts

Keine Salt-AES-Verschlüsselung in Python
Quadtree in Python --2
Python in der Optimierung
CURL in Python
Metaprogrammierung mit Python
Python 3.3 mit Anaconda
Geokodierung in Python
SendKeys in Python
Metaanalyse in Python
Unittest in Python
Epoche in Python
Deutsch in Python
DCI in Python
Quicksort in Python
nCr in Python
AES256 mit Python
N-Gramm in Python
Programmieren mit Python
Plink in Python
Konstante in Python
Private Methoden und Felder in Python [Verschlüsselung]
FizzBuzz in Python
SQLite in Python
Schritt AIC in Python
LINE-Bot [0] in Python
CSV in Python
Reverse Assembler mit Python
Reflexion in Python
Konstante in Python
nCr in Python.
Format in Python
PPAP in Python
Quad-Tree in Python
Reflexion in Python
Chemie mit Python
Hashbar in Python
DirectLiNGAM in Python
LiNGAM in Python
In Python reduzieren
In Python flach drücken
Sortierte Liste in Python
Täglicher AtCoder # 36 mit Python
Clustertext in Python
AtCoder # 2 jeden Tag mit Python
Täglicher AtCoder # 32 in Python
Täglicher AtCoder # 6 in Python
Täglicher AtCoder # 18 in Python
Bearbeiten Sie Schriftarten in Python
Dateioperationen in Python
Lesen Sie DXF mit Python
Täglicher AtCoder # 53 in Python
Tastenanschlag in Python
Verwenden Sie config.ini mit Python
Täglicher AtCoder # 33 in Python
Löse ABC168D in Python
Logistische Verteilung in Python
Täglicher AtCoder # 7 in Python
LU-Zerlegung in Python