def decrypt_data(encryption_key, data, iv=None): """ Function to decrypt the outData in the result Parameters: - encryption_key is the key used to decrypt the encrypted data of the response. - iv is an initialization vector if required by the data encryption algorithm. The default is all zeros. - data is the parameter data in outData part of workorder request as per TCF API 6.1.7 Work Order Data Formats. Returns decrypted data as a string """ if not data: logger.debug("Outdata is empty, nothing to decrypt") return data data_byte = crypto.base64_to_byte_array(data) logger.debug("encryption_key: %s", encryption_key) if iv is not None: decrypt_result = crypto.SKENC_DecryptMessage(encryption_key, iv, data_byte) else: decrypt_result = crypto.SKENC_DecryptMessage(encryption_key, data_byte) result = crypto.byte_array_to_string(decrypt_result) logger.info("Decryption result at client - %s", result) return result
def decrypt_data(encryption_key, iv, data): """ Function to decrypt the outData in the result Parameters: - encryption_key is the key used to decrypt the encrypted data of response. - iv is an initialization vector if required by the data encryption algorithm. The default is all zeros. - data is the parameter data in outData part of workorder request as per TCF API 6.1.7 Work Order Data Formats """ if not data: logger.debug("Outdata is empty, nothing to decrypt") return data_byte = crypto.base64_to_byte_array(data) logger.debug("encrypted_session_key: %s", encryption_key) decrypt_result = crypto.SKENC_DecryptMessage(encryption_key, crypto.hex_to_byte_array(iv), data_byte) result = base64.b64decode(crypto.byte_array_to_base64(decrypt_result)) logger.info("Decryption Result at Client - %s ", result)
"test failed: not detected.") sys.exit(-1) except Exception as exc: if (type(exc) == ValueError): logger.debug( "Symmetric encryption invalid iv detection test successful!") else: logger.error( "ERROR: Symmetric encryption invalid iv detection " + "test failed: ", exc) sys.exit(-1) try: ciphertext = crypto.SKENC_EncryptMessage(key, iv, msg) print(len(ciphertext)) crypto.SKENC_DecryptMessage(key, iv, ciphertext) except Exception as exc: logger.error("ERROR: Symmetric encryption test failed: ", exc) sys.exit(-1) if (bytearray(plaintext) == bytearray(msg)): logger.debug("Symmetric encryption/decryption test successful!") else: logger.error("ERROR:Symmetric encryption/decryption test failed: " + "decrypted text and plaintext mismatch.") exit(-1) c = list(ciphertext) c[0] = c[0] + 1 ciphertext = tuple(c) try: