Lines Matching refs:rsa

30 You can use the :py:func:`rsa.newkeys` function to create a keypair:
32 >>> import rsa
33 >>> (pubkey, privkey) = rsa.newkeys(512)
35 Alternatively you can use :py:meth:`rsa.PrivateKey.load_pkcs1` and
36 :py:meth:`rsa.PublicKey.load_pkcs1` to load keys from a file:
38 >>> import rsa
41 >>> privkey = rsa.PrivateKey.load_pkcs1(keydata)
61 >>> (pubkey, privkey) = rsa.newkeys(512, poolsize=8)
97 To encrypt or decrypt a message, use :py:func:`rsa.encrypt` resp.
98 :py:func:`rsa.decrypt`. Let's say that Alice wants to send a message
105 >>> import rsa
106 >>> (bob_pub, bob_priv) = rsa.newkeys(512)
117 >>> import rsa
118 >>> crypto = rsa.encrypt(message, bob_pub)
122 >>> message = rsa.decrypt(crypto, bob_priv)
139 :py:class:`rsa.pkcs1.DecryptionError`. If you want to be *sure*, use
140 :py:func:`rsa.sign`.
142 >>> crypto = rsa.encrypt(b'hello', bob_pub)
144 >>> rsa.decrypt(crypto, bob_priv)
147 rsa.pkcs1.DecryptionError: Decryption failed
153 :py:class:`rsa.pkcs1.DecryptionError` exception. It shows where
163 :py:func:`rsa.core.encrypt_int` and :py:func:`rsa.core.decrypt_int`
170 :py:func:`rsa.sign` function:
172 >>> (pubkey, privkey) = rsa.newkeys(512)
174 >>> signature = rsa.sign(message, privkey, 'SHA-1')
177 possible, check the :py:func:`rsa.sign` function documentation for
182 private key on remote server). To hash a message use the :py:func:`rsa.compute_hash`
183 function and then use the :py:func:`rsa.sign_hash` function to sign the hash:
186 >>> hash = rsa.compute_hash(message, 'SHA-1')
187 >>> signature = rsa.sign_hash(hash, privkey, 'SHA-1')
189 In order to verify the signature, use the :py:func:`rsa.verify`
193 >>> rsa.verify(message, signature, pubkey)
197 :py:class:`rsa.pkcs1.VerificationError` is thrown:
200 >>> rsa.verify(message, signature, pubkey)
203 File "/home/sybren/workspace/python-rsa/rsa/pkcs1.py", line 289, in verify
205 rsa.pkcs1.VerificationError: Verification failed
210 :py:class:`rsa.pkcs1.VerificationError` exception. It shows where
215 Instead of a message you can also call :py:func:`rsa.sign` and
216 :py:func:`rsa.verify` with a :py:class:`file`-like object. If the
221 ... signature = rsa.sign(msgfile, privkey, 'SHA-1')
224 ... rsa.verify(msgfile, signature, pubkey)
248 >>> import rsa.randnum
249 >>> aes_key = rsa.randnum.read_random_bits(128)
252 #. :py:func:`Encrypt <rsa.encrypt>` the AES key with RSA
254 >>> encrypted_aes_key = rsa.encrypt(aes_key, public_rsa_key)
283 .. _issue #19 on GitHub: https://github.com/sybrenstuvel/python-rsa/issues/13