Converting a key in bytes to use with openssl - 'bad magic number' - encryption

I'm trying to decrypt an AES protected XML. I have the key used to encrypt it but am struggling to apply it to the decryption process. This is part of an exercise and the key has been supplied accordingly.
The Key (Bytes) used is:
[0]: 137
[1]: 67
[2]: 248
[3]: 114
[4]: 168
[5]: 126
[6]: 229
[7]: 255
[8]: 147
[9]: 249
[10]: 177
[11]: 191
[12]: 131
[13]: 184
[14]: 242
[15]: 194
[16]: 93
[17]: 98
[18]: 209
[19]: 245
[20]: 211
[21]: 122
[22]: 198
[23]: 89
[24]: 15
[25]: 215
[26]: 137
[27]: 237
[28]: 193
[29]: 202
[30]: 126
[31]: 50
I am struggling to do this though. When using node to convert the above into a password I can use with openSSL, I get an error: bad magic number.
Node code to convert the above into a base64 string:
const bytes = [137, 67, 248, 114, 168, 126, 229, 255, 147, 249, 177, 191, 131, 184, 242, 194, 93, 98, 209, 245, 211, 122, 198, 89, 15, 215, 137, 237, 193, 202, 126, 50];
const base64Key = new Buffer.from(bytes).toString('base64'); // iUP4cqh+5f+T+bG/g7jywl1i0fXTesZZD9eJ7cHKfjI=
The openssl command I am using to try and decrypt the file (using the output above):
openssl enc -aes-256-cbc -base64 -pass pass:iUP4cqh+5f+T+bG/g7jywl1i0fXTesZZD9eKfjI= -d -p -in secretmessage.txt -out notsosecret.txt // bad magic number
I'm not sure where I am going wrong but the bad magic number leads me to believe I am not reading the provided key correctly. Questions:
Is my hypothesis that the key is being misread correct?
Is the key correct but being used incorrectly?
Does 'bad magic number' mean something else entirely?
Thanks in advance!

Related

InvalidArgumentError Traceback (most recent call last)

I've created a simple CNN with two main labels. The imput_shape was changed from 300 to 224 and the batch_size is 128. What am I supposed to do?
After entering this code:
history = model.fit(
train_ds,
validation_data=val_ds,
epochs = 20,
verbose = 2)
I got following error message:
Epoch 1/20
---------------------------------------------------------------------------
InvalidArgumentError Traceback (most recent call last)
Input In [63], in <cell line: 1>()
----> 1 history = model.fit(
2 train_ds,
3 validation_data=val_ds,
4 epochs = 20,
5 verbose = 2)
File ~\AppData\Roaming\Python\Python39\site-packages\keras\utils\traceback_utils.py:70, in filter_traceback.<locals>.error_handler(*args, **kwargs)
67 filtered_tb = _process_traceback_frames(e.__traceback__)
68 # To get the full stack trace, call:
69 # `tf.debugging.disable_traceback_filtering()`
---> 70 raise e.with_traceback(filtered_tb) from None
71 finally:
72 del filtered_tb
File ~\AppData\Roaming\Python\Python39\site-packages\tensorflow\python\eager\execute.py:52, in quick_execute(op_name, num_outputs, inputs, attrs, ctx, name)
50 try:
51 ctx.ensure_initialized()
---> 52 tensors = pywrap_tfe.TFE_Py_Execute(ctx._handle, device_name, op_name,
53 inputs, attrs, num_outputs)
54 except core._NotOkStatusException as e:
55 if name is not None:
InvalidArgumentError: Graph execution error:
Detected at node 'sparse_categorical_crossentropy/SparseSoftmaxCrossEntropyWithLogits/SparseSoftmaxCrossEntropyWithLogits' defined at (most recent call last):
File "C:\Anaconda3\lib\runpy.py", line 197, in _run_module_as_main
return _run_code(code, main_globals, None,
File "C:\Anaconda3\lib\runpy.py", line 87, in _run_code
exec(code, run_globals)
File "C:\Anaconda3\lib\site-packages\ipykernel_launcher.py", line 16, in <module>
app.launch_new_instance()
File "C:\Anaconda3\lib\site-packages\traitlets\config\application.py", line 846, in launch_instance
app.start()
File "C:\Anaconda3\lib\site-packages\ipykernel\kernelapp.py", line 677, in start
self.io_loop.start()
File "C:\Anaconda3\lib\site-packages\tornado\platform\asyncio.py", line 199, in start
self.asyncio_loop.run_forever()
File "C:\Anaconda3\lib\asyncio\base_events.py", line 601, in run_forever
self._run_once()
File "C:\Anaconda3\lib\asyncio\base_events.py", line 1905, in _run_once
handle._run()
File "C:\Anaconda3\lib\asyncio\events.py", line 80, in _run
self._context.run(self._callback, *self._args)
File "C:\Anaconda3\lib\site-packages\ipykernel\kernelbase.py", line 471, in dispatch_queue
await self.process_one()
File "C:\Anaconda3\lib\site-packages\ipykernel\kernelbase.py", line 460, in process_one
await dispatch(*args)
File "C:\Anaconda3\lib\site-packages\ipykernel\kernelbase.py", line 367, in dispatch_shell
await result
File "C:\Anaconda3\lib\site-packages\ipykernel\kernelbase.py", line 662, in execute_request
reply_content = await reply_content
File "C:\Anaconda3\lib\site-packages\ipykernel\ipkernel.py", line 360, in do_execute
res = shell.run_cell(code, store_history=store_history, silent=silent)
File "C:\Anaconda3\lib\site-packages\ipykernel\zmqshell.py", line 532, in run_cell
return super().run_cell(*args, **kwargs)
File "C:\Anaconda3\lib\site-packages\IPython\core\interactiveshell.py", line 2863, in run_cell
result = self._run_cell(
File "C:\Anaconda3\lib\site-packages\IPython\core\interactiveshell.py", line 2909, in _run_cell
return runner(coro)
File "C:\Anaconda3\lib\site-packages\IPython\core\async_helpers.py", line 129, in _pseudo_sync_runner
coro.send(None)
File "C:\Anaconda3\lib\site-packages\IPython\core\interactiveshell.py", line 3106, in run_cell_async
has_raised = await self.run_ast_nodes(code_ast.body, cell_name,
File "C:\Anaconda3\lib\site-packages\IPython\core\interactiveshell.py", line 3309, in run_ast_nodes
if await self.run_code(code, result, async_=asy):
File "C:\Anaconda3\lib\site-packages\IPython\core\interactiveshell.py", line 3369, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "C:\Users\local_sms92\Temp\ipykernel_43944\602300899.py", line 1, in <cell line: 1>
history = model.fit(
File "C:\Users\sms92\AppData\Roaming\Python\Python39\site-packages\keras\utils\traceback_utils.py", line 65, in error_handler
return fn(*args, **kwargs)
File "C:\Users\sms92\AppData\Roaming\Python\Python39\site-packages\keras\engine\training.py", line 1650, in fit
tmp_logs = self.train_function(iterator)
File "C:\Users\sms92\AppData\Roaming\Python\Python39\site-packages\keras\engine\training.py", line 1249, in train_function
return step_function(self, iterator)
File "C:\Users\sms92\AppData\Roaming\Python\Python39\site-packages\keras\engine\training.py", line 1233, in step_function
outputs = model.distribute_strategy.run(run_step, args=(data,))
File "C:\Users\sms92\AppData\Roaming\Python\Python39\site-packages\keras\engine\training.py", line 1222, in run_step
outputs = model.train_step(data)
File "C:\Users\sms92\AppData\Roaming\Python\Python39\site-packages\keras\engine\training.py", line 1024, in train_step
loss = self.compute_loss(x, y, y_pred, sample_weight)
File "C:\Users\sms92\AppData\Roaming\Python\Python39\site-packages\keras\engine\training.py", line 1082, in compute_loss
return self.compiled_loss(
File "C:\Users\sms92\AppData\Roaming\Python\Python39\site-packages\keras\engine\compile_utils.py", line 265, in __call__
loss_value = loss_obj(y_t, y_p, sample_weight=sw)
File "C:\Users\sms92\AppData\Roaming\Python\Python39\site-packages\keras\losses.py", line 152, in __call__
losses = call_fn(y_true, y_pred)
File "C:\Users\sms92\AppData\Roaming\Python\Python39\site-packages\keras\losses.py", line 284, in call
return ag_fn(y_true, y_pred, **self._fn_kwargs)
File "C:\Users\sms92\AppData\Roaming\Python\Python39\site-packages\keras\losses.py", line 2098, in sparse_categorical_crossentropy
return backend.sparse_categorical_crossentropy(
File "C:\Users\sms92\AppData\Roaming\Python\Python39\site-packages\keras\backend.py", line 5633, in sparse_categorical_crossentropy
res = tf.nn.sparse_softmax_cross_entropy_with_logits(
Node: 'sparse_categorical_crossentropy/SparseSoftmaxCrossEntropyWithLogits/SparseSoftmaxCrossEntropyWithLogits'
Received a label value of 2 which is outside the valid range of [0, 2). Label values: 1 2 2 2 2 2 2 2 2 2 1 2 2 1 2 1 1 2 1 1 2 2 1 1 1 2 2 2 2 2 2 2 1 2 2 2 2 2 1 2 2 2 1 2 2 1 2 2 1 2 2 1 1 2 1 1 2 2 2 1
[[{{node sparse_categorical_crossentropy/SparseSoftmaxCrossEntropyWithLogits/SparseSoftmaxCrossEntropyWithLogits}}]] [Op:__inference_train_function_38939]
(I've already tried to modify the imput_shape to 224, as recommended on other platforms, but this didn't work)
I think you need to change your output label to 0 & 1, instead of 1 & 2, since the error message shows that:
Node: 'sparse_categorical_crossentropy/SparseSoftmaxCrossEntropyWithLogits/SparseSoftmaxCrossEntropyWithLogits'
Received a label value of 2 which is outside the valid range of [0, 2).

How to solve 1064 error PyMySQL in Jupyter notebook?

I am using PyMySQLto create a simple table as a practice, but I can't create the table and getting this error: "ProgrammingError: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax"
Can anyone point my mistake?
The code:
# CREATE TABLE
# open connection
connection = pymysql.connect(cnx['host'],cnx['username'],cnx['password'],cnx['db'])
# open cursor
cursor = connection.cursor()
# query for creating table
create_table = """
CREATE TABLE classroom (
student_id INTEGER PRIMARY KEY,
name VARCHAR(20),
gender CMAR(1),
physics_marks INTEGER,
chemistry_marks INTEGER,
mathematics_marks INTEGER
);"""
# execute query
cursor.execute (create_table)
# commit changes
connection.commit()
# close connection
connection.close()
The error:
---------------------------------------------------------------------------
ProgrammingError Traceback (most recent call last)
<ipython-input-34-358e0fa696d2> in <module>
15 );"""
16 # execute query
---> 17 cursor.execute (create_table)
18 # commit changes
19 connection.commit()
~\AppData\Local\Continuum\anaconda3\lib\site-packages\pymysql\cursors.py in execute(self, query, args)
168 query = self.mogrify(query, args)
169
--> 170 result = self._query(query)
171 self._executed = query
172 return result
~\AppData\Local\Continuum\anaconda3\lib\site-packages\pymysql\cursors.py in _query(self, q)
326 self._last_executed = q
327 self._clear_result()
--> 328 conn.query(q)
329 self._do_get_result()
330 return self.rowcount
~\AppData\Local\Continuum\anaconda3\lib\site-packages\pymysql\connections.py in query(self, sql, unbuffered)
515 sql = sql.encode(self.encoding, 'surrogateescape')
516 self._execute_command(COMMAND.COM_QUERY, sql)
--> 517 self._affected_rows = self._read_query_result(unbuffered=unbuffered)
518 return self._affected_rows
519
~\AppData\Local\Continuum\anaconda3\lib\site-packages\pymysql\connections.py in _read_query_result(self, unbuffered)
730 else:
731 result = MySQLResult(self)
--> 732 result.read()
733 self._result = result
734 if result.server_status is not None:
~\AppData\Local\Continuum\anaconda3\lib\site-packages\pymysql\connections.py in read(self)
1073 def read(self):
1074 try:
-> 1075 first_packet = self.connection._read_packet()
1076
1077 if first_packet.is_ok_packet():
~\AppData\Local\Continuum\anaconda3\lib\site-packages\pymysql\connections.py in _read_packet(self, packet_type)
682
683 packet = packet_type(buff, self.encoding)
--> 684 packet.check_error()
685 return packet
686
~\AppData\Local\Continuum\anaconda3\lib\site-packages\pymysql\protocol.py in check_error(self)
218 errno = self.read_uint16()
219 if DEBUG: print("errno =", errno)
--> 220 err.raise_mysql_exception(self._data)
221
222 def dump(self):
~\AppData\Local\Continuum\anaconda3\lib\site-packages\pymysql\err.py in raise_mysql_exception(data)
107 errval = data[3:].decode('utf-8', 'replace')
108 errorclass = error_map.get(errno, InternalError)
--> 109 raise errorclass(errno, errval)
ProgrammingError: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'CMAR(1),\n physics_marks INTEGER,\n chemistr' at line 4")
Been a while since I have played with MySQL with python... Looks like some of the table field keys are incorrect (From what I'm used to seeing). Maybe try this and see how you go.
create_table = """
CREATE TABLE classroom (
student_id INT(11) AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(20) NOT NULL,
gender CHAR(1) NOT NULL,
physics_marks INT(4) NOT NULL,
chemistry_marks INT(4) NOT NULL,
mathematics_marks INT(4) NOT NULL,
);"""

UnboundLocalError: local variable 'key_schema' referenced before assignment

Im trying to integrate DAX with Pynamodb(working on an existing pull request). While testing the batch write method from aws DAX sdk I'm facing the below issue. Any help is appreciated.
/.virtualenvs/PynamoDB/lib/python2.7/site-packages/amazondax/DaxClient.pyc in batch_write_item(self, **kwargs)
98 Stubs.write_batchWriteItem_116217951_1(request, tube)
99
--> 100 result = self._decode_result('BatchWriteItem', request, Assemblers.batchWriteItem_116217951_1, tube)
101 result = self._resolve_attribute_values(result, tube)
102 return result
/.virtualenvs/PynamoDB/lib/python2.7/site-packages/amazondax/DaxClient.pyc in _decode_result(self, operation_name, request, assembler, tube)
223 if status == DaxClient.SUCCESS:
224 tube.skip() # Throw away the empty error header
--> 225 return assembler(request, tube)
226 else:
227 return self._handle_error(operation_name, tube)
/.virtualenvs/PynamoDB/lib/python2.7/site-packages/amazondax/Assemblers.pyc in batchWriteItem_116217951_1(request, tube)
115
116 for _ in range(num_items, 0, -2):
--> 117 key = AttributeValueDecoder._decode_key_bytes(_dec, key_schema)
118 if _dec.try_decode_null():
119 # DeleteRequest
UnboundLocalError: local variable 'key_schema' referenced before assignment
This is a known issue that I hope to have a fix out for shortly.
This is fixed in version 1.0.4 of the DAX Python client.

InactiveScopeException After Installing FOSCommentBundle

I am setting up FOSCommentBundle, I followed all steps to install it however any page I access now, I am getting the exception below:
InactiveScopeException: You cannot create a service
("fos_comment.listener.thread_permalink") of an inactive scope ("request").
in C:\htdocs\click-na-ilha\app\cache\dev\appDevDebugProjectContainer.php line 1595
at appDevDebugProjectContainer->getFosComment_Listener_ThreadPermalinkService() in C:\htdocs\click-na-ilha\app\bootstrap.php.cache line 1904
at Container->get('fos_comment.listener.thread_permalink') in C:\htdocs\click-na-ilha\app\cache\dev\classes.php line 1772
at ContainerAwareEventDispatcher->lazyLoad('fos_comment.thread.create') in C:\htdocs\click-na-ilha\app\cache\dev\classes.php line 1737
at ContainerAwareEventDispatcher->getListeners(null) in C:\htdocs\click-na-ilha\vendor\symfony\symfony\src\Symfony\Component\HttpKernel\Debug\TraceableEventDispatcher.php line 107
at TraceableEventDispatcher->getListeners() in C:\htdocs\click-na-ilha\vendor\symfony\symfony\src\Symfony\Component\HttpKernel\Debug\TraceableEventDispatcher.php line 168
at TraceableEventDispatcher->getNotCalledListeners() in C:\htdocs\click-na-ilha\vendor\symfony\symfony\src\Symfony\Component\HttpKernel\Debug\TraceableEventDispatcher.php line 354
at TraceableEventDispatcher->saveInfoInProfile(object(Profile), false) in C:\htdocs\click-na-ilha\vendor\symfony\symfony\src\Symfony\Component\HttpKernel\Debug\TraceableEventDispatcher.php line 328
at TraceableEventDispatcher->updateProfiles('05b179', false) in C:\htdocs\click-na-ilha\vendor\symfony\symfony\src\Symfony\Component\HttpKernel\Debug\TraceableEventDispatcher.php line 431
at TraceableEventDispatcher->postDispatch('kernel.terminate', object(PostResponseEvent)) in C:\htdocs\click-na-ilha\vendor\symfony\symfony\src\Symfony\Component\HttpKernel\Debug\TraceableEventDispatcher.php line 148
at TraceableEventDispatcher->dispatch('kernel.terminate', object(PostResponseEvent)) in C:\htdocs\click-na-ilha\app\bootstrap.php.cache line 2758
at HttpKernel->terminate(object(Request), object(Response)) in C:\htdocs\click-na-ilha\app\bootstrap.php.cache line 2159
at Kernel->terminate(object(Request), object(Response)) in C:\htdocs\click-na-ilha\web\app_dev.php line 32
Here is the code I have added https://gist.github.com/dextervip/3d9efe24c7241a6eeda0
What's wrong?

Symfony 2 DOMDocument::schemaValidateSource() error

I am using symfony 2 and I have a working webpage on my computer. The problem is that when I upload it to the production server I receive the following error:
ErrorException: Warning: DOMDocument::schemaValidateSource() [domdocument.schemavalidatesource]: Invalid Schema in /home/ljrgwoej/public_html/webs/Chambalo/vendor/symfony/src/Symfony/Component/DependencyInjection/Loader/XmlFileLoader.php line 363
in /home/ljrgwoej/public_html/webs/Chambalo/vendor/symfony/src/Symfony/Component/HttpKernel/Debug/ErrorHandler.php line 67
at ErrorHandler->handle()
at DOMDocument->schemaValidateSource() in /home/ljrgwoej/public_html/webs/Chambalo/vendor/symfony/src/Symfony/Component/DependencyInjection/Loader/XmlFileLoader.php line 363
at XmlFileLoader->validateSchema() in /home/ljrgwoej/public_html/webs/Chambalo/vendor/symfony/src/Symfony/Component/DependencyInjection/Loader/XmlFileLoader.php line 293
at XmlFileLoader->validate() in /home/ljrgwoej/public_html/webs/Chambalo/vendor/symfony/src/Symfony/Component/DependencyInjection/Loader/XmlFileLoader.php line 222
at XmlFileLoader->parseFile() in /home/ljrgwoej/public_html/webs/Chambalo/vendor/symfony/src/Symfony/Component/DependencyInjection/Loader/XmlFileLoader.php line 40
at XmlFileLoader->load() in /home/ljrgwoej/public_html/webs/Chambalo/vendor/symfony/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php line 43
at FrameworkExtension->load() in /home/ljrgwoej/public_html/webs/Chambalo/vendor/symfony/src/Symfony/Component/DependencyInjection/Compiler/MergeExtensionConfigurationPass.php line 42
at MergeExtensionConfigurationPass->process() in /home/ljrgwoej/public_html/webs/Chambalo/vendor/symfony/src/Symfony/Component/HttpKernel/DependencyInjection/MergeExtensionConfigurationPass.php line 39
at MergeExtensionConfigurationPass->process() in /home/ljrgwoej/public_html/webs/Chambalo/vendor/symfony/src/Symfony/Component/DependencyInjection/Compiler/Compiler.php line 119
at Compiler->compile() in /home/ljrgwoej/public_html/webs/Chambalo/vendor/symfony/src/Symfony/Component/DependencyInjection/ContainerBuilder.php line 437
at ContainerBuilder->compile() in /home/ljrgwoej/public_html/webs/Chambalo/app/bootstrap.php.cache line 872
at Kernel->buildContainer() in /home/ljrgwoej/public_html/webs/Chambalo/app/bootstrap.php.cache line 783
at Kernel->initializeContainer() in /home/ljrgwoej/public_html/webs/Chambalo/app/bootstrap.php.cache line 517
at Kernel->boot() in /home/ljrgwoej/public_html/webs/Chambalo/app/bootstrap.php.cache line 548
at Kernel->handle() in /home/ljrgwoej/public_html/webs/Chambalo/web/app.php line 12
what could I do? i have google a lot with no results. Thanks
I got this after I did an update. I fixed this by downgrading my version of libxml from libxml2-2.6.26-2.1.21.el5_9.2 to libxml2-2.6.26-2.1.21.el5_9.1.
yum downgrade libxml2-2.6.26-2.1.21.el5_9.1

Resources