Cryptography functions¶
-
RANDOM
(bloc_size=8)¶ Returns a block_size long random hexadecimal string
Parameters: bloc_size (int) – the size in bye of the random string. Returns str rand_str: the random hexadecimal string.
-
ISO_9797_M1_Padding_left
(data, bloc_size=8)¶ Performs a ISO_9797_M1 Padding by left. This padding is done in the following way: before the original data null bytes is added in order for the whole block to have a length in bytes that is a multiple of bloc_size If original data length is already a multiple of bloc_size, no padding is needed
Parameters: - data (str) – Hexadecimal string to pad.
- bloc_size (int) – the block size modulus
Returns str data_pad: the padded data.
-
ISO_9797_M1_Padding
(data, bloc_size=8)¶ Performs a ISO_9797_M1 Padding. This padding is done in the following way: after the original data null bytes is added in order for the whole block to have a length in bytes that is a multiple of bloc_size If original data length is already a multiple of bloc_size, no padding is needed
Parameters: - data (str) – Hexadecimal string to pad.
- bloc_size (int) – the block size modulus
Returns str data_pad: the padded data.
-
ISO_9797_M2_Padding_left
(data, bloc_size=8)¶ Performs a ISO_9797_M2 Padding by left. This padding is done in the following way: before the original data a byte ‘80’ is added in order for the whole block to have a length in bytes that is a multiple of bloc_size If original data length is already a multiple of bloc_size, no padding is needed
Parameters: - data (str) – Hexadecimal string to pad.
- bloc_size (int) – the block size modulus
Returns str data_pad: the padded data.
-
ISO_9797_M2_Padding
(data, bloc_size=8)¶ Performs a ISO_9797_M2 Padding. This padding is done in the following way: after the original data a byte ‘80’ and then null bytes are added. Then, in order for the whole block to have a length in bytes that is a multiple of bloc_size, null bytes can be added (byte ‘80’ and null bytes are optional and not present in case the length is already a multiple of bloc_size)
Parameters: - data (str) – Hexadecimal string to pad.
- bloc_size (int) – the block size modulus
Returns str data_pad: the padded data.
-
Remove_ISO_9797_M2_Padding
(data)¶ Remove a ISO_9797_M2 Padding from an hexadecimal string .
Parameters: - data (str) – Hexadecimal string to unpad.
- bloc_size (int) – the block size modulus
Returns str data_pad: the unpadded data.
-
RSA_PKCS_1_Padding
(data, key_size=1024)¶ Performs a PKCS_1 Padding use to sign data with a RSA Private Key. The generated block of data is:
Leading Block Type Padding Data 00 01 | FF…FF 00 D Parameters: - data (str) – Hexadecimal string to pad.
- key_size (int) – the RSA key size that will be used to sign data.
Returns str padded_data: the data padded
-
DES_CBC
(data, key, iv='0000000000000000')¶ Performs a DES CBC on the hexadecimal string using the specified key and the specified initial vector
Parameters: - data (str) – Hexadecimal string to cipher.
- key (str) – the key to use
- iv (str) – the initial vector (0000000000000000 by default)
Returns str data_ret: the ciphered data.
-
DES_INV_CBC
(data, key, iv='0000000000000000')¶ Performs a DES-1 CBC on the hexadecimal string using the specified key and the specified initial vector
Parameters: - data (str) – Hexadecimal string to decipher.
- key (str) – the key to use
- iv (str) – the initial vector (0000000000000000 by default)
Returns str data_ret: the deciphered data.
-
DES_ECB
(data, key)¶ Performs a DES ECB on the hexadecimal string using the specified key
Parameters: - data (str) – Hexadecimal string to cipher.
- key (str) – the key to use
Returns str data_ret: the ciphered data.
-
DES_INV_ECB
(data, key)¶ Performs a DES-1 ECB on the hexadecimal string using the specified key
Parameters: - data (str) – Hexadecimal string to decipher.
- key (str) – the key to use
Returns str data_ret: the deciphered data.
-
DES3_CBC
(data, key, iv='0000000000000000')¶ Performs a 3DES CBC on the hexadecimal string using the specified key and the specified initial vector
Parameters: - data (str) – Hexadecimal string to cipher.
- key (str) – the key to use
- iv (str) – the initial vector (0000000000000000 by default)
Returns str data_ret: the ciphered data.
-
DES3_INV_CBC
(data, key, iv='0000000000000000')¶ Performs a 3DES-1 CBC on the hexadecimal string using the specified key and the specified initial vector
Parameters: - data (str) – Hexadecimal string to decipher.
- key (str) – the key to use
- iv (str) – the initial vector (0000000000000000 by default)
Returns str data_ret: the deciphered data.
-
DES3_ECB
(data, key)¶ Performs a 3DES ECB on the hexadecimal string using the specified key
Parameters: - data (str) – Hexadecimal string to cipher.
- key (str) – the key to use
Returns str data_ret: the ciphered data.
-
DES3_INV_ECB
(data, key)¶ Performs a 3DES-1 ECB on the hexadecimal string using the specified key
Parameters: - data (str) – Hexadecimal string to cipher.
- key (str) – the key to use
Returns str data_ret: the ciphered data.
-
AES_CMAC
(data, key)¶ Performs a AES CMAC on the hexadecimal string using the specified key
Parameters: - data (str) – Hexadecimal string to cipher.
- key (str) – the key to use
Returns str data_ret: the ciphered data.
-
AES_ECB
(data, key)¶ Performs a AES ECB on the hexadecimal string using the specified key
Parameters: - data (str) – Hexadecimal string to cipher.
- key (str) – the key to use
Returns str data_ret: the ciphered data.
-
AES_CBC
(data, key, iv='00000000000000000000000000000000')¶ Performs a AES CBC on the hexadecimal string using the specified key and the specified initial vector
Parameters: - data (str) – Hexadecimal string to cipher.
- key (str) – the key to use
- iv (str) – the initial vector (00000000000000000000000000000000 by default)
Returns str data_ret: the ciphered data.
-
AES_INV_ECB
(data, key)¶ Performs a AES-1 ECB on the hexadecimal string using the specified key
Parameters: - data (str) – Hexadecimal string to decipher.
- key (str) – the key to use
Returns str data_ret: the deciphered data.
-
AES_INV_CBC
(data, key, iv='00000000000000000000000000000000')¶ Performs a AES-1 CBC on the hexadecimal string using the specified key and the specified initial vector
Parameters: - data (str) – Hexadecimal string to decipher.
- key (str) – the key to use
- iv (str) – the initial vector (00000000000000000000000000000000 by default)
Returns str data_ret: the deciphered data.
-
MAC33
(data, key, iv='0000000000000000')¶ Performs a MAC33 on the hexadecimal string using the specified key and the specified initial vector
Parameters: - data (str) – Hexadecimal string to mac.
- key (str) – the key to use
- iv (str) – the initial vector (0000000000000000 by default)
Returns str data_ret: the MAC33 of the data.
-
MAC3
(data, key, padding='ISO_9797_M2', iv='0000000000000000')¶ Performs a MAC3 on the hexadecimal string using the specified key and the specified initial vector
Parameters: - data (str) – Hexadecimal string to mac.
- key (str) – the key to use
- padding (str) – the padding method to use. Could be ISO_9797_M1, ISO_9797_M2 (default), None
- iv (str) – the initial vector (0000000000000000 by default)
Returns str data_ret: the MAC3 of the data.
-
MAC
(data, key, iv='0000000000000000')¶ Performs a MAC on the hexadecimal string using the specified key and the specified initial vector
Parameters: - data (str) – Hexadecimal string to mac.
- key (str) – the key to use
- iv (str) – the initial vector (0000000000000000 by default)
Returns str data_ret: the MAC of the data.
-
SHA1
(data)¶ Performs the SHA-1 algorithm on hexadecimal data
Parameters: data (str) – Hexadecimal string. Returns str data_ret: the hash data.
-
SHA224
(data)¶ Performs the SHA-224 algorithm on hexadecimal data
Parameters: data (str) – Hexadecimal string. Returns str data_ret: the hash data.
-
SHA256
(data)¶ Performs the SHA-256 algorithm on hexadecimal data
Parameters: data (str) – Hexadecimal string. Returns str data_ret: the hash data.
-
SHA384
(data)¶ Performs the SHA-384 algorithm on hexadecimal data
Parameters: data (str) – Hexadecimal string. Returns str data_ret: the hash data.
-
SHA512
(data)¶ Performs the SHA-512 algorithm on hexadecimal data
Parameters: data (str) – Hexadecimal string. Returns str data_ret: the hash data.
-
MD5
(data)¶ Performs the MD5 algorithm on hexadecimal data
Parameters: data (str) – Hexadecimal string. Returns str data_ret: the hash data.
-
generate_RSA_keys
(exponent, key_size=1024)¶ RSA keys generation
Parameters: - exponent (str) – the public key exponent.
- key_size (int) – the key size in bit (1024 by default).
Returns tuple data_ret: the private and public key objects
-
build_RSA_keys
(public_modulus, public_exponent, p, q, d, dmp1, dmq1, iqmp)¶ Build RSA keys using specific values
Parameters: - public_modulus (str) – the public key modulus.
- public_exponent (str) – the public key exponent.
- p (str) – the private key large_modulus
- q (str) – the private key small_modulus
- d (str) – The private key exponent
- dmp1 (str) – the key component d mod (p-1)
- dmq1 (str) – the key component d mod (q-1)
- iqmp (str) – the key component q-1 mod p
Returns tuple data_ret: the private and public key objects
-
RSA_signature
(message, private_key, padding_algorithm='PKCS1', hash_algorithm='SHA1')¶ Performs a RSA signature on data using the padding and hash algorithm.
Parameters: - message (str) – the message to sign as hexadecimal string.
- private_key (str) – the private key object see
build_RSA_keys()
orgenerate_RSA_keys()
- padding_algorithm (str) – the padding to apply on data. Could be ‘PKCS1’, ‘PSS’ or ‘OEAP’
- hash_algorithm (str) – the hash algorithm if the message you want to sign has already been hashed. Could be ‘SHA1’, ‘SHA224’, ‘SHA256’, ‘SHA384’ or ‘SHA512’
Returns str data_ret: the signature
-
RSA_verify
(message, signature, public_key, padding_algorithm='PKCS1', hash_algorithm='SHA1')¶ Performs a RSA signature verification on data using the padding and hash algorithm.
Parameters: - message (str) – the message to sign as hexadecimal string.
- signature (str) – the signature of the message.
- public_key (str) – the public key object see
build_RSA_keys()
orgenerate_RSA_keys()
- padding_algorithm (str) – the padding to apply on data. Could be ‘PKCS1’, ‘PSS’ or ‘OEAP’
- hash_algorithm (str) – the hash algorithm if the message you want to sign has already been hashed. Could be ‘SHA1’, ‘SHA224’, ‘SHA256’, ‘SHA384’ or ‘SHA512’
Returns bool data_ret: True if the signature is verified, False otherwize
-
ECDSA_signature
(message, private_key, hash_algorithm='SHA1')¶ Performs a ECDSA signature on data using hash algorithm.
Parameters: - message (str) – the message to sign as hexadecimal string.
- private_key (str) – the private key object see
build_ECDSA_keys()
orgenerate_ECDSA_keys()
- hash_algorithm (str) – the hash algorithm if the message you want to sign has already been hashed. Could be ‘SHA1’, ‘SHA224’, ‘SHA256’, ‘SHA384’ or ‘SHA512’
Returns str data_ret: the signature
-
ECDSA_verify
(message, signature, public_key, hash_algorithm='SHA1')¶ Performs a ECDSA signature verification on data using the hash algorithm.
Parameters: - message (str) – the message to sign as hexadecimal string.
- signature (str) – the signature of the message.
- public_key (str) – the public key object see
build_EC_keys()
orgenerate_EC_keys()
- hash_algorithm (str) – the hash algorithm if the message you want to sign has already been hashed. Could be ‘SHA1’, ‘SHA224’, ‘SHA256’, ‘SHA384’ or ‘SHA512’
Returns bool data_ret: True if the signature is verified, False otherwize
-
generate_ECDH_key_agreement
(private_key, public_key)¶ Performs a ECDH key aggrement.
Parameters: - private_key (str) – the private key object see
build_EC_keys()
orgenerate_EC_keys()
- public_key (str) – the public key object see
build_EC_keys()
orgenerate_EC_keys()
Returns str data_ret: The agreed key
- private_key (str) – the private key object see
-
generate_EC_keys
(curve_name='brainpoolP256r1')¶ EC keys generation
Parameters: curve_name (str) – the name of the curve. Possible curve names: Value Description “nistP521r1” NIST P-521 “nistP256r1” NIST P-256 “brainpoolP192r1” Brainpool P-192 R1 “brainpoolP192t1” Brainpool P-192 T1 “brainpoolP256r1” Brainpool P-256 R1 “brainpoolP256t1” Brainpool P-256 T1 “brainpoolP384r1” Brainpool P-384 R1 “brainpoolP384t1” Brainpool P-384 T1 “brainpoolP512r1” Brainpool P-512 R1 “brainpoolP512t1” Brainpool P-512 T1 Returns tuple data_ret: the private and public key objects
-
build_EC_keys
(s, x, y, curve_name='brainpoolP256r1')¶ Build EC keys using parameters
Parameters: - s (str) – The private value
- x (str) – The affine x component of the public point
- y (str) – The affine y component of the public point
- curve_name (str) – the name of the curve. Possible curve names:
Value Description “nistP521r1” NIST P-521 “nistP256r1” NIST P-256 “brainpoolP192r1” Brainpool P-192 R1 “brainpoolP192t1” Brainpool P-192 T1 “brainpoolP256r1” Brainpool P-256 R1 “brainpoolP256t1” Brainpool P-256 T1 “brainpoolP384r1” Brainpool P-384 R1 “brainpoolP384t1” Brainpool P-384 T1 “brainpoolP512r1” Brainpool P-512 R1 “brainpoolP512t1” Brainpool P-512 T1 Returns tuple data_ret: the private and public key objects