PyFoam.Infrastructure.Authentication module
Simple public key authentication with RSA based on the implementation http://code.activestate.com/recipes/578797-public-key-encryption-rsa/
- class PyFoam.Infrastructure.Authentication.Key(exponent, modulus)
Bases:
tuple- __getnewargs__()
Return self as a plain tuple. Used by copy and pickle.
- __match_args__ = ('exponent', 'modulus')
- __module__ = 'PyFoam.Infrastructure.Authentication'
- static __new__(_cls, exponent, modulus)
Create new instance of Key(exponent, modulus)
- __repr__()
Return a nicely formatted representation string
- __slots__ = ()
- _asdict()
Return a new dict which maps field names to their values.
- _field_defaults = {}
- _fields = ('exponent', 'modulus')
- classmethod _make(iterable)
Make a new Key object from a sequence or iterable
- _replace(**kwds)
Return a new Key object replacing specified fields with new values
- exponent
Alias for field number 0
- modulus
Alias for field number 1
- class PyFoam.Infrastructure.Authentication.KeyPair(public, private)
Bases:
tuple- __getnewargs__()
Return self as a plain tuple. Used by copy and pickle.
- __match_args__ = ('public', 'private')
- __module__ = 'PyFoam.Infrastructure.Authentication'
- static __new__(_cls, public, private)
Create new instance of KeyPair(public, private)
- __repr__()
Return a nicely formatted representation string
- __slots__ = ()
- _asdict()
Return a new dict which maps field names to their values.
- _field_defaults = {}
- _fields = ('public', 'private')
- classmethod _make(iterable)
Make a new KeyPair object from a sequence or iterable
- _replace(**kwds)
Return a new KeyPair object replacing specified fields with new values
- private
Alias for field number 1
- public
Alias for field number 0
- PyFoam.Infrastructure.Authentication.key_to_str(key)[source]
Convert Key to string representation >>> key_to_str(Key(50476910741469568741791652650587163073, 95419691922573224706255222482923256353)) ‘25f97fd801214cdc163796f8a43289c1:47c92a08bc374e96c7af66eb141d7a21’
- PyFoam.Infrastructure.Authentication.keygen(n, public=None)[source]
Generate public and private keys from primes up to N.
Optionally, specify the public key exponent (65537 is popular choice).
>>> pubkey, privkey = keygen(2**64) >>> msg = 123456789012345 >>> coded = pow(msg, *pubkey) >>> plain = pow(coded, *privkey) >>> assert msg == plain
- PyFoam.Infrastructure.Authentication.multinv(modulus, value)[source]
Multiplicative inverse in a given modulus
>>> multinv(191, 138) 18 >>> multinv(191, 38) 186 >>> multinv(120, 23) 47
- PyFoam.Infrastructure.Authentication.str_to_key(key_str)[source]
Convert string representation to Key (assuming valid input) >>> (str_to_key(‘25f97fd801214cdc163796f8a43289c1:47c92a08bc374e96c7af66eb141d7a21’) == … Key(exponent=50476910741469568741791652650587163073, modulus=95419691922573224706255222482923256353)) True