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

Where is the PEM file format specified?

For quite a long time, there was no formal specification of the PEM format with regards to cryptographic exchange of information. PEM is the textual encoding, but what is actually being encoded depends on the context. In April 2015, the IETF approved RFC 7468, which finally documents how various implementations exchange data using PEM textual … Read more

How to cryptographically hash a JSON object?

The problem is a common one when computing hashes for any data format where flexibility is allowed. To solve this, you need to canonicalize the representation. For example, the OAuth1.0a protocol, which is used by Twitter and other services for authentication, requires a secure hash of the request message. To compute the hash, OAuth1.0a says … Read more

Given a private key, is it possible to derive its public key?

In most asymmetrical crypto system implementation, the only fact that is ensured is that you cannot find the private key from the public key. The other way round, finding the public key from the private key is trivial in most case. For instance, in RSA, you can create public key from private key with: openssl … Read more

AES string encryption in Objective-C

This line near the top says you’re adding AES functionality to NSMutableData: @implementation NSMutableData(AES) In Objective-C, this is called a category; categories let you extend an existing class. This code would typically go in a file named NSMutableData-AES.m. Create a header file too, NSMutableData-AES.h. It should contain: @interface NSMutableData(AES) – (NSMutableData*) EncryptAES: (NSString *) key; … Read more

Android encryption

The java AES library has a flaw in it that allows, under the right circumstances, a listener to decrypt the packets sent. See Padding Oracle Exploit Tool vs Apache MyFaces. That being said check out this SO question Java 256bit AES Encryption. Bouncy Castle AES EXAMPLE stolen from: http://www.java2s.com/Code/Java/Security/EncryptionanddecryptionwithAESECBPKCS7Padding.htm import javax.crypto.Cipher; import javax.crypto.spec.SecretKeySpec; public class … Read more