Sybren A. Stüvel | 062b132 | 2011-08-03 14:46:49 +0200 | [diff] [blame] | 1 | Compatibility with standards |
Sybren A. Stüvel | 3934ab4 | 2016-02-05 16:01:20 +0100 | [diff] [blame] | 2 | ============================ |
Sybren A. Stüvel | a3fd61a | 2011-07-31 00:22:31 +0200 | [diff] [blame] | 3 | |
Sybren A. Stüvel | c1c455d | 2011-08-01 23:04:30 +0200 | [diff] [blame] | 4 | .. index:: OpenSSL |
| 5 | .. index:: compatibility |
| 6 | |
Sybren A. Stüvel | a3fd61a | 2011-07-31 00:22:31 +0200 | [diff] [blame] | 7 | Python-RSA implements encryption and signatures according to PKCS#1 |
| 8 | version 1.5. This makes it compatible with the OpenSSL RSA module. |
| 9 | |
| 10 | Keys are stored in PEM or DER format according to PKCS#1 v1.5. Private |
| 11 | keys are compatible with OpenSSL. However, OpenSSL uses X.509 for its |
| 12 | public keys, which are not supported. |
| 13 | |
Sybren A. Stüvel | dbea213 | 2011-08-03 13:31:57 +0200 | [diff] [blame] | 14 | Encryption: |
Sybren A. Stüvel | a3fd61a | 2011-07-31 00:22:31 +0200 | [diff] [blame] | 15 | PKCS#1 v1.5 with at least 8 bytes of random padding |
| 16 | |
Sybren A. Stüvel | dbea213 | 2011-08-03 13:31:57 +0200 | [diff] [blame] | 17 | Signatures: |
Sybren A. Stüvel | a3fd61a | 2011-07-31 00:22:31 +0200 | [diff] [blame] | 18 | PKCS#1 v1.5 using the following hash methods: |
| 19 | MD5, SHA-1, SHA-256, SHA-384, SHA-512 |
| 20 | |
Sybren A. Stüvel | dbea213 | 2011-08-03 13:31:57 +0200 | [diff] [blame] | 21 | Private keys: |
Sybren A. Stüvel | a3fd61a | 2011-07-31 00:22:31 +0200 | [diff] [blame] | 22 | PKCS#1 v1.5 in PEM and DER format, ASN.1 type RSAPrivateKey |
| 23 | |
Sybren A. Stüvel | dbea213 | 2011-08-03 13:31:57 +0200 | [diff] [blame] | 24 | Public keys: |
Sybren A. Stüvel | a3fd61a | 2011-07-31 00:22:31 +0200 | [diff] [blame] | 25 | PKCS#1 v1.5 in PEM and DER format, ASN.1 type RSAPublicKey |
| 26 | |
Sybren A. Stüvel | dbea213 | 2011-08-03 13:31:57 +0200 | [diff] [blame] | 27 | :ref:`VARBLOCK <bigfiles>` encryption: |
Sybren A. Stüvel | 1d14c4e | 2017-04-10 11:31:09 +0200 | [diff] [blame] | 28 | Deprecated in Python-RSA 3.4 and removed from Python-RSA 4.0. |
| 29 | Was Python-RSA only, not compatible with any other known application. |
Sybren A. Stüvel | a3fd61a | 2011-07-31 00:22:31 +0200 | [diff] [blame] | 30 | |
Sybren A. Stüvel | 58fe946 | 2011-08-03 13:56:32 +0200 | [diff] [blame] | 31 | .. _openssl: |
Sybren A. Stüvel | a3fd61a | 2011-07-31 00:22:31 +0200 | [diff] [blame] | 32 | |
Sybren A. Stüvel | 58fe946 | 2011-08-03 13:56:32 +0200 | [diff] [blame] | 33 | Interoperability with OpenSSL |
Sybren A. Stüvel | 3934ab4 | 2016-02-05 16:01:20 +0100 | [diff] [blame] | 34 | ----------------------------- |
Sybren A. Stüvel | a3fd61a | 2011-07-31 00:22:31 +0200 | [diff] [blame] | 35 | |
Sybren A. Stüvel | 58fe946 | 2011-08-03 13:56:32 +0200 | [diff] [blame] | 36 | You can create a 512-bit RSA key in OpenSSL as follows:: |
Sybren A. Stüvel | a3fd61a | 2011-07-31 00:22:31 +0200 | [diff] [blame] | 37 | |
Sybren A. Stüvel | 58fe946 | 2011-08-03 13:56:32 +0200 | [diff] [blame] | 38 | openssl genrsa -out myprivatekey.pem 512 |
| 39 | |
| 40 | To get a Python-RSA-compatible public key from OpenSSL, you need the |
| 41 | private key first, then run it through the ``pyrsa-priv2pub`` |
| 42 | command:: |
| 43 | |
| 44 | pyrsa-priv2pub -i myprivatekey.pem -o mypublickey.pem |
| 45 | |
| 46 | Encryption and decryption is also compatible:: |
| 47 | |
| 48 | $ echo hello there > testfile.txt |
| 49 | $ pyrsa-encrypt -i testfile.txt -o testfile.rsa publickey.pem |
| 50 | $ openssl rsautl -in testfile.rsa -inkey privatekey.pem -decrypt |
| 51 | hello there |
Sybren A. Stüvel | d92b667 | 2011-07-31 17:44:44 +0200 | [diff] [blame] | 52 | |
Sybren A. Stüvel | 7cf95f4 | 2014-02-22 11:21:45 +0100 | [diff] [blame] | 53 | Interoperability with PKCS#8 |
Sybren A. Stüvel | 3934ab4 | 2016-02-05 16:01:20 +0100 | [diff] [blame] | 54 | ---------------------------- |
Sybren A. Stüvel | 7cf95f4 | 2014-02-22 11:21:45 +0100 | [diff] [blame] | 55 | |
| 56 | The standard PKCS#8 is widely used, and more complex than the PKCS#1 |
| 57 | v1.5 supported by Python-RSA. In order to extract a key from the |
| 58 | PKCS#8 format you need an external tool such as OpenSSL:: |
| 59 | |
| 60 | openssl rsa -in privatekey-pkcs8.pem -out privatekey.pem |
| 61 | |
| 62 | You can then extract the corresponding public key as described above. |