blob: d6e1dc4e5e9978a80683f79bab4815df75a5385d [file] [log] [blame]
Sybren A. Stüvel062b1322011-08-03 14:46:49 +02001Compatibility with standards
Sybren A. Stüvel3934ab42016-02-05 16:01:20 +01002============================
Sybren A. Stüvela3fd61a2011-07-31 00:22:31 +02003
Sybren A. Stüvelc1c455d2011-08-01 23:04:30 +02004.. index:: OpenSSL
5.. index:: compatibility
6
Sybren A. Stüvela3fd61a2011-07-31 00:22:31 +02007Python-RSA implements encryption and signatures according to PKCS#1
8version 1.5. This makes it compatible with the OpenSSL RSA module.
9
10Keys are stored in PEM or DER format according to PKCS#1 v1.5. Private
11keys are compatible with OpenSSL. However, OpenSSL uses X.509 for its
12public keys, which are not supported.
13
Sybren A. Stüveldbea2132011-08-03 13:31:57 +020014Encryption:
Sybren A. Stüvela3fd61a2011-07-31 00:22:31 +020015 PKCS#1 v1.5 with at least 8 bytes of random padding
16
Sybren A. Stüveldbea2132011-08-03 13:31:57 +020017Signatures:
Sybren A. Stüvela3fd61a2011-07-31 00:22:31 +020018 PKCS#1 v1.5 using the following hash methods:
19 MD5, SHA-1, SHA-256, SHA-384, SHA-512
20
Sybren A. Stüveldbea2132011-08-03 13:31:57 +020021Private keys:
Sybren A. Stüvela3fd61a2011-07-31 00:22:31 +020022 PKCS#1 v1.5 in PEM and DER format, ASN.1 type RSAPrivateKey
23
Sybren A. Stüveldbea2132011-08-03 13:31:57 +020024Public keys:
Sybren A. Stüvela3fd61a2011-07-31 00:22:31 +020025 PKCS#1 v1.5 in PEM and DER format, ASN.1 type RSAPublicKey
26
Sybren A. Stüveldbea2132011-08-03 13:31:57 +020027:ref:`VARBLOCK <bigfiles>` encryption:
Sybren A. Stüvel1d14c4e2017-04-10 11:31:09 +020028 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üvela3fd61a2011-07-31 00:22:31 +020030
Sybren A. Stüvel58fe9462011-08-03 13:56:32 +020031.. _openssl:
Sybren A. Stüvela3fd61a2011-07-31 00:22:31 +020032
Sybren A. Stüvel58fe9462011-08-03 13:56:32 +020033Interoperability with OpenSSL
Sybren A. Stüvel3934ab42016-02-05 16:01:20 +010034-----------------------------
Sybren A. Stüvela3fd61a2011-07-31 00:22:31 +020035
Sybren A. Stüvel58fe9462011-08-03 13:56:32 +020036You can create a 512-bit RSA key in OpenSSL as follows::
Sybren A. Stüvela3fd61a2011-07-31 00:22:31 +020037
Sybren A. Stüvel58fe9462011-08-03 13:56:32 +020038 openssl genrsa -out myprivatekey.pem 512
39
40To get a Python-RSA-compatible public key from OpenSSL, you need the
41private key first, then run it through the ``pyrsa-priv2pub``
42command::
43
44 pyrsa-priv2pub -i myprivatekey.pem -o mypublickey.pem
45
46Encryption 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üveld92b6672011-07-31 17:44:44 +020052
Sybren A. Stüvel7cf95f42014-02-22 11:21:45 +010053Interoperability with PKCS#8
Sybren A. Stüvel3934ab42016-02-05 16:01:20 +010054----------------------------
Sybren A. Stüvel7cf95f42014-02-22 11:21:45 +010055
56The standard PKCS#8 is widely used, and more complex than the PKCS#1
57v1.5 supported by Python-RSA. In order to extract a key from the
58PKCS#8 format you need an external tool such as OpenSSL::
59
60 openssl rsa -in privatekey-pkcs8.pem -out privatekey.pem
61
62You can then extract the corresponding public key as described above.