How to use the rsa.key function in rsa

To help you get started, we’ve selected a few rsa examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github sybrenstuvel / python-rsa / tests / test_key.py View on Github external
def test_exponents_coefficient_calculation(self):
        pk = rsa.key.PrivateKey(3727264081, 65537, 3349121513, 65063, 57287)

        self.assertEqual(pk.exp1, 55063)
        self.assertEqual(pk.exp2, 10095)
        self.assertEqual(pk.coef, 50797)
github googleapis / google-auth-library-python / tests / crypt / test__python_rsa.py View on Github external
def test_from_string_pub_key(self):
        verifier = _python_rsa.RSAVerifier.from_string(PUBLIC_KEY_BYTES)
        assert isinstance(verifier, _python_rsa.RSAVerifier)
        assert isinstance(verifier._pubkey, rsa.key.PublicKey)
github sybrenstuvel / python-rsa / tests / test_key.py View on Github external
def test_custom_exponent(self):
        priv, pub = rsa.key.newkeys(16, exponent=3)

        self.assertEqual(3, priv.e)
        self.assertEqual(3, pub.e)
github googleapis / oauth2client / tests / test__pure_python_crypt.py View on Github external
def test_from_string_pkcs1(self):
        key_bytes = self._load_pkcs1_key_bytes()
        signer = crypt.RsaSigner.from_string(key_bytes)
        self.assertIsInstance(signer, crypt.RsaSigner)
        self.assertIsInstance(signer._key, rsa.key.PrivateKey)
github googleapis / oauth2client / tests / test__pure_python_crypt.py View on Github external
def test_from_string_pub_key(self):
        public_key = self._load_public_key_bytes()
        verifier = crypt.RsaVerifier.from_string(
            public_key, is_x509_cert=False)
        self.assertIsInstance(verifier, crypt.RsaVerifier)
        self.assertIsInstance(verifier._pubkey, rsa.key.PublicKey)
github sybrenstuvel / python-rsa / runme.py View on Github external
#!/usr/bin/python

import sys
import rsa

from rsa import key

pub = key.PublicKey(31698122414741849421263704398157795847591, 65537)

priv = key.PrivateKey(31698122414741849421263704398157795847591, 65537,
    7506520894712811128876594754922157377793, 4169414332984308880603,
    7602535963858869797)

print "Running rsa.verify(verslag, pub)..."

crypto = open('verslag.crypt').read()
verslag = rsa.verify(crypto, pub)

print "Decryption done, press enter to read"
sys.stdin.readline()
print verslag

print "Generating public & private keypair for demonstrational purposes..."
(pub, priv) = rsa.newkeys(256)
github alangpierce / appengine-python3 / google / appengine / api / app_identity / app_identity_keybased_stub.py View on Github external
if email_address is None:
      raise ValueError('Email address for service account must be specified.')
    self.__email_address = email_address
    if private_key_path is None:
      raise ValueError('Path to the private key must be specified '
                       'if an email address is specified.')
    if not os.path.exists(private_key_path):
      raise ValueError(private_key_path + ' not found.')
    if private_key_path.endswith('.p12'):

      raise ValueError(('Please convert .p12 format to .pem format: '
                        'cat %s | openssl pkcs12 -nodes -nocerts -passin '
                        'pass:notasecret | openssl rsa > %s') % (
                            private_key_path,
                            '%s.pem' % os.path.splitext(private_key_path)[0]))
    self.__private_key = rsa.key.PrivateKey.load_pkcs1(
        file(private_key_path, 'rb').read(), 'PEM')
    self.__access_token_cache = {}
    self.__x509 = None
    self.__signing_key = None
github taxigps / xbmc-addons-chinese / plugin.video.bdyun / resources / modules / rsa / bigfile.py View on Github external
.. _documentation: https://stuvel.eu/python-rsa-doc/usage.html#working-with-big-files

    :param infile: file-like object to read the crypto in VARBLOCK format from
    :param outfile: file-like object to write the cleartext to
    :param priv_key: :py:class:`rsa.PrivateKey` to decrypt with

    """

    warnings.warn("The 'rsa.bigfile.decrypt_bigfile' function was deprecated in Python-RSA version "
                  "3.4 due to security issues in the VARBLOCK format. See "
                  "https://stuvel.eu/python-rsa-doc/usage.html#working-with-big-files "
                  "for more information.",
                  DeprecationWarning, stacklevel=2)

    if not isinstance(priv_key, key.PrivateKey):
        raise TypeError('Private key required, but got %r' % priv_key)

    for block in varblock.yield_varblocks(infile):
        cleartext = pkcs1.decrypt(block, priv_key)
        outfile.write(cleartext)
github n1nj4sec / pupy / pupy / pupylib / PupyCredentials.py View on Github external
def _generate_rsa_keypair(bits=2048):
    key = RSA.gen_key(bits, 65537)
    private_key = key.as_pem(cipher=None)
    rsa_privkey = rsa.key.PrivateKey.load_pkcs1(
        private_key, 'PEM'
    )
    rsa_pubkey = rsa.key.PublicKey(rsa_privkey.n, rsa_privkey.e)
    public_key = rsa_pubkey.save_pkcs1('PEM')

    return private_key, public_key, key
github n1nj4sec / pupy / pupy / pupylib / PupyCredentials.py View on Github external
def _generate_rsa_keypair(bits=2048):
    key = RSA.gen_key(bits, 65537)
    private_key = key.as_pem(cipher=None)
    rsa_privkey = rsa.key.PrivateKey.load_pkcs1(
        private_key, 'PEM'
    )
    rsa_pubkey = rsa.key.PublicKey(rsa_privkey.n, rsa_privkey.e)
    public_key = rsa_pubkey.save_pkcs1('PEM')

    return private_key, public_key, key