des

PyCrypto: Generate RSA key protected with DES3 password

半城伤御伤魂 提交于 2019-12-04 12:29:56
问题 I have been able to create a RSA key protected by password with DES3 (well... I think because I'm very new to this encryption world) by using the command: openssl genrsa -out "/tmp/myKey.pem" -passout pass:"f00bar" -des3 2048 Now, I would like to do that inside a Python script, using PyCrypto, if possible. I have seen this message, which seems to discourage the use of PyCrypto to do that. Is it still like that? Of course I can always call os.execute , and execute the above command, but I'd

DES/ECB/PKCS5Padding decryption in PHP

让人想犯罪 __ 提交于 2019-12-04 12:15:47
I'm in the need of decrypting with PHP (or Javascript) some service calls. I've spent all the day trying to accomplish, this, but I've been unable to decrypt it properly. As a reference, the service provider sent me the following decryption sample code in Java: DESKeySpec dks = new DESKeySpec("keyword".getBytes()); SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES"); SecretKey key = keyFactory.generateSecret(dks); Cipher cipher = Cipher.getInstance("DES/ECB/PKCS5Padding"); SecureRandom sr = new SecureRandom(); cipher.init( Cipher.DECRYPT_MODE, key ,sr); byte b[] = response

How should I create my DES key? Why is an 7-character string not enough?

前提是你 提交于 2019-12-04 11:13:37
I'm having a bit of difficulty getting an understand of key length requirements in cryptography. I'm currently using DES which I believe is 56 bits... now, by converting an 8 character password to a byte[] my cryptography works. If I use a 7 digit password, it doesn't. Now, forgive me if I'm wrong, but is that because ASCII characters are 7 bits, therefor 8 * 7 = 56bits? That just doesn't seem right to me. If I want to use a key, why can I not just pass in a salted hash of my secret key, i.e. an MD5 hash? I'm sure this is very simple, but I can't get a clear understanding of what's going on.

Replicate Java's PBEWithMD5AndDES in Python 2.7

笑着哭i 提交于 2019-12-04 10:01:23
问题 If it's not immediately obvious, let me start by saying I am not a crypto person. I have been tasked with replicating the behavior of Java's PBEWithMD5AndDES (MD5 digest with DES encryption) in Python 2.7. I do have access to Python's cryptography toolkit PyCrypto. Here is the Java code whose behavior I am trying to replicate: import java.security.spec.KeySpec; import javax.crypto.spec.PBEKeySpec; import javax.crypto.SecretKey; import javax.crypto.SecretKeyFactory; import java.security.spec

Triple DES encryption

泪湿孤枕 提交于 2019-12-04 07:46:22
Please note that the issue I am having here is with the key size . At first, based on the comments included in the below code, I figured that my key needed to be 24 bytes (192 bits). This didn't work so I gave 16, 32, and 8 byte keys a shot - nothing seems to be working. By "not working" I mean that after my text has been encrypted and decrypted it does not hold the same value as my original text. Example: Original Text: 'Example test this should work ' Encrypted Text: ¸ ¹pÕô6 Decrypted Text: 'Example ' Here are the two functions I am using (Encrypt / Decrypt functions). Also I will include

TripleDES key sizes - .NET vs Wikipedia

こ雲淡風輕ζ 提交于 2019-12-04 06:04:00
According to Wikipedia , TripleDES supports 56, 112, and 168-bit key lengths, but the System.Cryptography.TripleDESCryptoServiceProvider.LegalKeySizes says it only accepts 128 and 192-bit key lengths. The system I'm developing needs to be interoperable (data encrypted by my code needs to be decryptable in PHP, Java, and Objective-C) and I don't who is correct in this case. So who should I believe? And how can I be sure my encrypted data is portable? Wikipedia does not say TripleDES supports 56 bit keys. The "keying options" talk about "triple-length" keys and "double-length" keys, the latter

分组密码体制【密码学笔记】

与世无争的帅哥 提交于 2019-12-04 01:58:36
分组密码的基本概念 ​ 分组密码在加密过程中不是将明文按字符逐位加密,而是首先要将待加密的明文进行分组,每组的长度相同,然后对每组明文分别加密得到密文。加密和解密过程采用相同的密钥,称为对称密码体制。 ​ 例如将明文分为 \(m\) 块: \(P_{0},P_{1},P_2,…,P_{m-1}\) ,每个块在密钥作用下执行相同的变换,生成 \(m\) 个密文块: \(C_0,C_1,C_2,…,C_{m-1}\) ,每块的大小可以是任意长度,但通常是每块的大小大于等于64位(块大小为1比特位时,分组密码就变为序列密码)。 如下图所示是通信双方最常用的分组密码基本通信模型。 ​ 一个分组密码系统(Block Cipher System,简称BCS)可以用一个五元组来表示: \(BCS=\{P,C,K,E,D\}\) 。其中,P(plaintext)、C(ciphertext)、K(key)、E(encryption)、D(decode)分别代表明文空间、密文空间、密钥空间、加密算法、解密算法。 设 \(X=\{x_0,x_1,…,x_{n-2},x_{n-1}\}\) 为一组长度为 \(n\) 的明文块,在密钥 \(K=\{k_0,k_1,…,k_{t-1}\}\) 的加密作用下得到密文块 \(Y=\{y_0,y_1,…,y_{m-2},y_{m-1}\}\) ,其中 \(x_i,y

Decrypt ( with PHP ) a Java encryption ( PBEWithMD5AndDES )

岁酱吖の 提交于 2019-12-03 23:09:45
问题 Someone asked me to decrypt with PHP a string encrypted with the following Java Class. public class CryptoLibrary { private Cipher encryptCipher; private sun.misc.BASE64Encoder encoder = new sun.misc.BASE64Encoder(); public CryptoLibrary() throws SecurityException{ java.security.Security.addProvider(new com.sun.crypto.provider.SunJCE()); char[] pass = "NNSHHETJKKSNKH".toCharArray(); byte[] salt = { (byte) 0xa3, (byte) 0x21, (byte) 0x24, (byte) 0x2c, (byte) 0xf2, (byte) 0xd2, (byte) 0x3e,

How do you use the crypt library in C for DES encryption? (setkey, encrypt, crypt, etc.)

拥有回忆 提交于 2019-12-03 21:55:44
I need to do some simple DES encryption in C to interface with some old code. From what I understand you can use the "crypt" library for this, with the functions setkey, encrypt, crypt, etc. I have been messing with it and can't get it right. The example on the man page for setkey/encrypt is lacking. I want to get the same output as I would be able to get with some java code (see below). So let's say I have two character arrays in C. char *message = "hellothe"; char *key = "iamakey0"; Can someone give an example of how to encrypt these with setkey/encrypt and get the same result as I would

Android DES Decrypt badpaddingexception: pad block corrupted

蓝咒 提交于 2019-12-03 21:31:02
First of all, I've reviewed all the entries on the forum, and I still can not find a solution to my problem. I have to measure the time it takes to encode and decode a text with DES, and make a comparison with other algorithms. When I run the code, I have this error: BadPaddingException: pad block corrupted . When I debug, the code fails in this line: byte [] plaintext = cipher.doFinal (cipherBytes); I use class Base64 to encode/decode String <--> byte[] Any idea? thanks private static final String CIPHER_ALGORITHM = "DES/ECB/PKCS5Padding"; private static int KEY_LENGTH = 64; public static