473,651 Members | 2,663 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Working with bytes.

I have been unable to solve a problem. I am working with MD5 signatures
trying to put these in a database. The MD5 signatures are not generated
using the python md5 module but an external application that is
producing the valid 16 byte signature formats. Anyway, these 16 byte
signatures are not nescarrally valid strings. How do I manipulate the
bytes? I need to concatenate the bytes with a SQL statement which is a
string. This works fine for most of the md5 signatures but some blow up
with a TypeError. Because there is a NULL byte or something else. So I
guess my ultimate question is how do I get a prepared SQL statement to
accept a series of bytes? How do I convert the bytes to a valid string
like:

'x%L9d\340\316\ 262\363\037\311 \345<\262\357\2 15'

that can be concatenated?

Thanks

Jul 18 '05 #1
2 2290
Adam T. Gautier wrote:
I have been unable to solve a problem. I am working with MD5 signatures
trying to put these in a database. The MD5 signatures are not generated
using the python md5 module but an external application that is
producing the valid 16 byte signature formats. Anyway, these 16 byte
signatures are not nescarrally valid strings. How do I manipulate the
bytes? I need to concatenate the bytes with a SQL statement which is a
string. This works fine for most of the md5 signatures but some blow up
with a TypeError. Because there is a NULL byte or something else. So I
guess my ultimate question is how do I get a prepared SQL statement to
accept a series of bytes? How do I convert the bytes to a valid string
like:

'x%L9d\340\316\ 262\363\037\311 \345<\262\357\2 15'

that can be concatenated?

Thanks

This should probably do:
cursor.execute( 'SELECT author from stored where md5 = ?', md5)

But you might consider changing your approach to store hex strings:
cursor.execute( 'SELECT author from stored where md5 = ?',
''.join(['%02x' % byte for byte in md5]))
--
-Scott David Daniels
Sc***********@A cm.Org
Jul 18 '05 #2
>>>>> "Adam T. Gautier" <ad**********@y ahoo.com> (ATG) wrote:

ATG> I have been unable to solve a problem. I am working with MD5 signatures
ATG> trying to put these in a database. The MD5 signatures are not generated
ATG> using the python md5 module but an external application that is producing
ATG> the valid 16 byte signature formats. Anyway, these 16 byte signatures are
ATG> not nescarrally valid strings. How do I manipulate the bytes? I need to
ATG> concatenate the bytes with a SQL statement which is a string. This works
ATG> fine for most of the md5 signatures but some blow up with a TypeError.
ATG> Because there is a NULL byte or something else. So I guess my ultimate
ATG> question is how do I get a prepared SQL statement to accept a series of
ATG> bytes? How do I convert the bytes to a valid string like:

ATG> 'x%L9d\340\316\ 262\363\037\311 \345<\262\357\2 15'

ATG> that can be concatenated?

Depends what the database accepts. If it supports BLOBs you could use
that. Otherwise convert them to hex, or base64.
See for example the the codecs module or the binascii module.

--
Piet van Oostrum <pi**@cs.uu.n l>
URL: http://www.cs.uu.nl/~piet [PGP]
Private email: P.***********@h ccnet.nl
Jul 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
6044
by: Larry Menard | last post by:
Folks, I've written the world's simplest java UDF, and it is complaining that it can't load the method. The class seems OK, it's complaining about the method. The JDBC Sample UDFs (e.g., scUDFReturningErr) seem to work fine, so I made sure that I'm doing everything the same way the sample is. My class file is in the right place. My method is public. I'm using the IBM 1.4.1 JDK that came with my DB2 (v8.2.2). I'm using the InfoCenter...
7
14577
by: Alex | last post by:
Hello people, I have a code written in JAVA that creates field of bytes: byte uuid = new byte; Now I have to translate this line into C++. I'm working in VS 6.0. (unfortunately I have to). Is there any class in MFC framework that I can use like bytes? Or I
8
5043
by: den 2005 | last post by:
Hi everybody, I am not sure where to put this in this forum. So, I posted this at several topics. I created a class library that has two public methods Encrypt() and Decrypt(). I reference this dll to a window application. I used DESCryptoServiceProvider Algorithm to encrypt and decrypt then with same Key and IV. But unable to decrypt it back to original text. This project I plan to use all algorithm and Hash. This is Phase One. There is...
4
3250
by: SpreadTooThin | last post by:
client: import socket s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect(("192.168.1.101", 8080)) print 'Connected' s.send('ABCD') buffer = s.recv(4) print buffer s.send('exit')
6
3398
by: RaulAbHK | last post by:
Dear all, I guess this is a basic question with an easy answer but I am a beginner and I would much apreciate your feedbacks. Let's say I have a library with some functionality to perform some image processing on jpeg images. One of functions in the library is similar to this: myfunction_effect (&out_instance, &mysettings, I8 *buf_in, I32
0
1306
by: George2 | last post by:
Hello everyone, I am using perfmon to watch the working set and virtual bytes, when I do a keyword search in SourceInsight. I found the value of working set is larger than virtual bytes when do a search, I am confused how could working set larger than virtual bytes? I have this confusion is virtual bytes is all things -- reserved, committed memory -- which includes RAM (working set) and page swap file. So, virtual bytes should be always...
0
1580
by: George2 | last post by:
Hello everyone, From the definition of working set, it is a subset of virtual pages resident in physical memory -- from book Windows Internals. It means working set could not be larger than virtual memory (subset relationship). But the following simple code on Windows Server 2003 proves (if you monitor virtual bytes counter and working set bytes conuter from perfmon), if we do not unmap the page map file, the working set will continue to...
3
2583
by: PrabodhanP | last post by:
I have CSS based mouseover scrolling for divContent embeded in my webpage.It works fine in IE,but not working in mozilla-FF. It is located at the location.. http://www.integrityads.net/fashions/collection.htm Also it is not resolution compatible,i.e. alignment totally messed up when i increased the resolution.Please suggest. Code is as follows:- <HTML><HEAD> <meta http-equiv="Content-Language" content="en-us"> <TITLE>Collections</TITLE>...
9
3210
by: RichG | last post by:
I'm working with a data stream of 8 bytes in an embedded application. In most cases the data is byte aligned so I can define a structure and then memcpy the data directly to the structure elements. There are, however, a few cases where the 16 bit data values span 2 or 3 bytes. I came up with a few macros to handle these cases. It's working fine, but I'm wondering if anyone can point out some obvious flaws or code optimizations to make the...
0
8352
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8275
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8802
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8697
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8579
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5612
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4283
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1909
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1587
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.