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
-
exponent
¶ Alias for field number 0
-
modulus
¶ Alias for field number 1
-
-
class
PyFoam.Infrastructure.Authentication.
KeyPair
(public, private)¶ Bases:
tuple
-
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