on 06-23-2016 12:49 PM
Hello Community,
I'm using PB 12.1 6639
I have a datatype related problem.
I have to AES-encrypt a Byte Array. For encrypting i use a third Party activeX (Crypt2 from Chilkat Software).
There is a function byte[] EncryptBytes(Byte data[]).
The value i have to crypt is a Long encoded as a signed two complement (big endian) (=Java Long).
For example a Long value of 102400 is stored in a Byte Array in that way:
Byte[1] = 1
Byte[2] = -112
Byte[3] = 0
And here starts the Trouble. PB's Byte datatype is a unsigned datatype and can hold only positive Byte values.
I also tried using a blob variable instead of a Byte Array (the function EncryptBytes takes it without error), but on Setting up
the data in the blob variable using Setbyte(blob, n, byte)-function there is the same problem that Setbyte only can handle positive Byte values.
So the question is how to incorporate negative Byte values into a Byte Array or a blob!
Hope somebody can help me.
Regards Martin
Hi Martin,
-112 = 0xFF90 in a WORD or 0x90 in a byte.
0x90 is 144, so you can try byte[2] = 144 or byte[2] = 256 + -112).
Regards
Bernhard
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you Chris, thank you Bernhard! @Bernhard: maybe I've not understand well what you mean, but on Setting Byte[2] to a value doesn't effect Byte[1], so there are still only postive values in the Array @chris: I'm also not sure what you mean by 'manipulate each signed byte', but maybe your comment lead me to a solution, that I think is working: the Magic word is Blobedit(). blob lbl_data Byte lbytes[] lbytes[1] = 0 lbl_data = Blob(lbytes) //initalialize the blob, for simplicity only 1 byte // edit the value in Byte one ll_rc = Blobedit(lbl_data, 1, 0) // Shows "0" Messagebox("", Long(lbl_data)) ll_rc = Blobedit(lbl_data, 1, 144) Messagebox("", Long(lbl_data)) // Shows "144" ll_rc = Blobedit(lbl_data, 1, -112) Messagebox("", Long(lbl_data)) // Shows "-112" you can see, that the conversion of a Byte in the blob back to a Long value Shows the correct original value. Do you agree, that my Interpretation is correct?
Hi Martin,
ll_Value = 102400
lblb_data = blob( space( 2 )) // 4byte
BlobEdit( lblb_Data, 1, ll_Value )
lby_Data[1] = byte( BlobMid( lblb_Data, 1, 1 )) // = 0
lby_Data[2] = byte( BlobMid( lblb_Data, 2, 1 )) // = 144
lby_Data[3] = byte( BlobMid( lblb_Data, 3, 1 )) // = 1
lby_Data[4] = byte( BlobMid( lblb_Data, 4, 1 )) // = 0
To get 1, 144, 0 you can use:
lby_Data[1] = byte( BlobMid( lblb_Data, 3, 1 )) // = 1
lby_Data[2] = byte( BlobMid( lblb_Data, 2, 1 )) // = 144
lby_Data[3] = byte( BlobMid( lblb_Data, 1, 1 )) // = 0
Regards
Bernhard
Hi Martin;
A very interesting question! One aspect of PB that I have not played with (negative byte) but I see your issue.
I wonder if the approach might be to use the BLOB data type as the PB byte array and then manipulate each signed byte in the blob using the Two's Compliment?
Regards ... Chris
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
93 | |
10 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.