When I try to write a specific byte (letter 'p') in a writable buffer using pack_into the result is a corrupted data: -
>>> from ctypes import create_string_buffer
-
>>> from struct import pack_into
-
>>> test = create_string_buffer(1)
-
>>> pack_into("B", test, 0, 48)
-
>>> print repr(test.raw)
-
'0'
-
The answer should be '\x30'. What I'm doing wrong?
3 2791
What are you trying to do? I've not really come across those commands before, and wonder if they are still relevant to modern versions of python?
Oh, by the way:
chr(48) = "0"
chr(112) = "p"
I use pack_into to build a buffer of bytes that are going to be the modulus of a public key. I think that the problem isn't what I suspected, the \x30 when wrote in a terminal is replaced by 'zero' as you said.
The main problem is to convert a DNSKEY (dns record) into a public key structure (RSA) of M2crypto. Today I'm doing the following: -
# Exponent and modulus must be in a string in OpenSSL's MPINT
-
# format - 4-byte big-endian bit-count followed by the appropriate
-
# number of bits
-
-
# Exponent
-
-
exponentFinal = create_string_buffer(4 + exponentSize)
-
exponentOffset = 0
-
-
pack_into(">L", exponentFinal, exponentOffset, exponentSize)
-
exponentOffset += 4
-
-
for i in range(0, exponentSize):
-
pack_into("B", exponentFinal, exponentOffset, ord(exponent[i]))
-
exponentOffset += 1
-
-
# Modulus
-
-
modulusSize = len(modulus)
-
modulusFinal = create_string_buffer(4 + modulusSize)
-
modulusOffset = 0
-
-
pack_into(">L", modulusFinal, modulusOffset, modulusSize)
-
modulusOffset += 4
-
-
for i in range(0, modulusSize):
-
pack_into("B", modulusFinal, modulusOffset, ord(modulus[i]))
-
modulusOffset += 1
-
-
try:
-
rsa = RSA.new_pub_key((exponentFinal.raw, modulusFinal.raw))
-
except RSA.RSAError, e:
-
return None
-
But something is wrong, because when I try to verify a signature with the public key a got an error telling that the modulus isn't compatible with data size.
Best regards,
Rafael
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Betty Hickman |
last post by:
I'm having trouble writing a 2D array to a binary file. Here's what I
have:
FILE *outfile;
short **clump_class;
clump_class = malloc(nrows * sizeof(short *));
for (i=0; i<nrows; ++i)...
|
by: James Harris |
last post by:
My K&R 2nd ed has in the Reference Manual appendix, A7.4.8 sizeof yields
the number of BYTES required to store an object of the type of its operand.
What happens if C is running on a machine that...
|
by: collinm |
last post by:
hi
i send a command to a led display, the led display is suppose to return
me some character
i write a string on a serial port
void ledDisplayExist()
{
char msg={'\0', '\0', '\0', '\0',...
|
by: Christopher Benson-Manica |
last post by:
(Followups set to comp.std.c. Apologies if the crosspost is unwelcome.)
strchr() is to strrchr() as strstr() is to strrstr(), but strrstr()
isn't part of the standard. Why not?
--...
|
by: Robert A. van Ginkel |
last post by:
In news:OZ0W9RsdDHA.2432@TK2MSFTNGP10.phx.gbl... I ask the question how I
can see if all the data is on the other side of the connection.
I got as answer that I should use the blocking property.
I...
|
by: PCH |
last post by:
I'm trying to pull a data file that has an image (jpeg) embedded in it.
I can locate the bytes for the image, but when I try to write it to a file,
the image ends up being corrupt!
the kb/b...
|
by: Jason |
last post by:
Could someone here show me how I would write a vb program to convert decimal
ip address to binary?
For example a small form with a convert button and a label for the result
and a textbox for the...
|
by: semedao |
last post by:
Hi , I am using asyc sockets p2p connection between 2 clients.
when I debug step by step the both sides , i'ts work ok.
when I run it , in somepoint (same location in the code)
when I want to...
|
by: andy.z |
last post by:
If 2 people try to access the same text file at the same time to write to
it - what happens in PHP ?
What I mean is - presumably the first will be ok -
But what will the second person actually...
|
by: Tzury Bar Yochay |
last post by:
Hi,
I can't find in the documentation the way to use these two functions.
can someone share a simple code that utilize these two functions?
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| |