Skip to content

keyutils

Paramecio2fm is a series of wrappers for Flask, mako and others and construct a simple headless cms.

Copyright (C) 2023 Antonio de la Rosa Caballero

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License along with this program. If not, see https://www.gnu.org/licenses/.

create_key(n=10)

Simple function for create a random string

Simple function for create a random string based in urandom function and base64 encoding

Parameters:

Name Type Description Default
n int

size of string random bytes (view urandom function in Python3 Help)

10
Source code in paramecio2/libraries/keyutils.py
51
52
53
54
55
56
57
58
59
60
61
62
63
def create_key(n=10):

    """ Simple function for create a random string

    Simple function for create a random string based in urandom function and base64 encoding

    Args:
        n (int): size of string random bytes (view urandom function in Python3 Help)
    """

    rand_bytes=urandom(n)

    return b64encode(rand_bytes).decode('utf-8')[0:-2]

create_key_encrypt(n=10)

Simple function for create a random string

Simple function for create a random string based in sha512

Parameters:

Name Type Description Default
n int

size of string random bytes (view urandom function in Python3 Help)

10
Source code in paramecio2/libraries/keyutils.py
28
29
30
31
32
33
34
35
36
37
def create_key_encrypt(n=10):
    """ Simple function for create a random string

    Simple function for create a random string based in sha512

    Args:
        n (int): size of string random bytes (view urandom function in Python3 Help)
    """

    return sha512(urandom(n)).hexdigest()

create_key_encrypt_256(n=10)

Simple function for create a random string

Simple function for create a random string based in sha256

Parameters:

Name Type Description Default
n int

size of string random bytes (view urandom function in Python3 Help)

10
Source code in paramecio2/libraries/keyutils.py
39
40
41
42
43
44
45
46
47
48
49
def create_key_encrypt_256(n=10):

    """ Simple function for create a random string

    Simple function for create a random string based in sha256

    Args:
        n (int): size of string random bytes (view urandom function in Python3 Help)
    """

    return sha256(urandom(n)).hexdigest()

create_simple_password(n=14)

Based in python3 documentation for create passwords using secrets module

https://docs.python.org/3/library/secrets.html

Parameters:

Name Type Description Default
n int

Number of random elements of the password

14
Source code in paramecio2/libraries/keyutils.py
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
def create_simple_password(n=14):

    """ Based in python3 documentation for create passwords using secrets module

    https://docs.python.org/3/library/secrets.html

    Args:
        n (int): Number of random elements of the password

    """

    password=''

    alphabet=string.ascii_letters+string.digits+string.punctuation

    while True:
        password=''.join(secrets.choice(alphabet) for i in range(n))
        if (any(c.islower() for c in password) and any(c.isupper() for c in password) and sum(c.isdigit() for c in password) >= 3):
            break

    return password