How to encrypt text with a password in python?

Here’s how to do it properly in CBC mode, including PKCS#7 padding: import base64 from Crypto.Cipher import AES from Crypto.Hash import SHA256 from Crypto import Random def encrypt(key, source, encode=True): key = SHA256.new(key).digest() # use SHA-256 over our key to get a proper-sized AES key IV = Random.new().read(AES.block_size) # generate IV encryptor = AES.new(key, AES.MODE_CBC, … Read more

AES/CBC/PKCS5Padding vs AES/CBC/PKCS7Padding with 256 key size performance java

The block size is a property of the used cipher algorithm. For AES it is always 16 bytes. So strictly speaking, PKCS5Padding cannot be used with AES since it is defined only for a block size of 8 bytes. I assume, AES/CBC/PKCS5Padding is interpreted as AES/CBC/PKCS7Padding internally. The only difference between these padding schemes is … Read more

NSData-AES Class Encryption/Decryption in Cocoa

Why not use the built-in encryption algorithms? Here’s an NSData+AES i wrote which uses CCCrypt with a 256it key for AES256 encryption. You can use it like: NSData *data = [[NSData dataWithContentsOfFile:@”/etc/passwd”] encryptWithString:@”mykey”]; and decrypt it with: NSData *file = [data decryptWithString:@”mykey”]; DISCLAIMER: There no guarantee my NSData+AES is bug-free 🙂 It’s fairly new. I … Read more