How to decrypt OpenSSL AES-encrypted files in Python?

OpenSSL provides a popular (but insecure – see below!) command line interface for AES encryption: openssl aes-256-cbc -salt -in filename -out filename.enc Python has support for AES in the shape of the PyCrypto package, but it only provides the tools. How to use Python/PyCrypto to decrypt files that have been encrypted using OpenSSL? Notice This … Read more

How to create a secure random AES key in Java?

What is the recommended way of generating a secure, random AES key in Java, using the standard JDK? In other posts, I have found this, but using a SecretKeyFactory might be a better idea: KeyGenerator keyGen = KeyGenerator.getInstance(“AES”); SecureRandom random = new SecureRandom(); // cryptograph. secure random keyGen.init(random); SecretKey secretKey = keyGen.generateKey(); It would be … Read more

SHA1 VS RSA: what’s the difference between them?

What are the differences between SHA1 and RSA? Are they just different algorithms or are they fundamentally (i.e. used for different things) different on some level. Answer Fundamentally different. SHA1 is a hash algorithm, which is a one way function, turning an input of any size into a fixed-length output (160 bit in this case). … Read more

Problems converting byte array to string and back to byte array

There are a lot of questions with this topic, the same solution, but this doesn’t work for me. I have a simple test with an encryption. The encryption/decryption itself works (as long as I handle this test with the byte array itself and not as Strings). The problem is that don’t want to handle it … Read more

getting a IllegalBlockSizeException: Data must not be longer than 256 bytes when using rsa

I am using rsa key to encrypt a long string which I will send to my server(will encrypt it with server’s public key and my private key) But it throws an exception like javax.crypto.IllegalBlockSizeException: Data must not be longer than 256 bytes I feel that I have not understood the working of rsa properly till … Read more

PEM_read_bio_PrivateKey() returns NULL in ECB mode only

PEM_read_bio_PrivateKey() returns NULL if a private key is encrypted by DES EDE in ECB mode. The issue happens in EVP_DecryptFinal_ex(): 4128:error:06065064:digital envelope routines:EVP_DecryptFinal_ex:bad decrypt:evp_enc.c:330: If the same private key is encrypted by DES EDE in CBC mode, this function works OK. I checked, this issue is reproducible on openssl 0.9.8r/y versions (without FIPS). If openssl … Read more

Specified key is not a valid size for this algorithm

I have with this code: RijndaelManaged rijndaelCipher = new RijndaelManaged(); // Set key and IV rijndaelCipher.Key = Convert.FromBase64String(“ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz012345678912”); rijndaelCipher.IV = Convert.FromBase64String(“1234567890123456789012345678901234567890123456789012345678901234”); I get throws : Specified key is not a valid size for this algorithm. Specified initialization vector (IV) does not match the block size for this algorithm. What’s wrong with this strings ? Can … Read more

How can I hide or encrypt JavaScript code? [duplicate]

This question already has answers here: How can I obfuscate (protect) JavaScript? [closed] (22 answers) Closed 6 years ago. Is there any way to hide or encrypt JavaScript code to prevent people from viewing, copying, and/or modifying proprietary programs? Answer You can obfuscate it, but there’s no way of protecting it completely. example obfuscator: … Read more