Android Java create hex string and convert it to byte array and back


HOME ยป Java

I want to achieve something in my android application. I need to
create a HEX representation of a String variable in my class and to
convert it to byte array. Something like this :


String
hardcodedStr = "SimpleText";
String hexStr =
someFuncForConvert2HEX(hardcodedStr); // this should be the HEX
string
byte[] hexStr2BArray = hexStr.getBytes();
/>

and after that I want to be able to convert this
hexStr2BArray to String and get it's value. Something
like this :


String hexStr = new String(hexStr2BArray,
"UTF-8");
String firstStr = someFuncConvertHEX2Str(hexStr); //
the result must be : "Si

Declaration of a method are following:


//some.h />void TDES_Decryption(BYTE *Data, BYTE *Key, BYTE *InitalVector, int
Length);

I am calling this method from the
following code:


//some.c
extern "C"
__declspec(dllexport) bool _cdecl OnDecryption(LPCTSTR stringKSN,
LPCTSTR BDK){
TDES_Decryption(m_Track1Buffer, m_cryptoKey,
init_vector, len);
return m_Track1Buffer;
} />

Where as data type of m_Track1Buffer is
BYTE m_Track1Buffer[1000];
Now i want to make some
changes in above method i.e. want to return the String in he

C & C++ & C#

The PDF Document Hex String generated by postgres is like:

/>%PDF-1.51512%26526526526515121 0
obj1512<</Type/Catalog/Pages 2 0 R/Lang(en-IN)
/StructTreeRoot 32 0 R/MarkInfo<</Marked
true>>>>1512endobj15122 0
obj1512<</Type/Pages/Count 4/Kids[ 3 0 R 15 0 R 22 0 R
29 0 R] >>1512endobj15123 0
obj1512<</Type/Page/Parent 2 0
R/Resources<</Font<</F1 5 0 R/F2 7 0 R/F3
9 0 R/F4 13 0
R>>/ProcSet[/PDF/Text/ImageB/ImageC/ImageI]
>>/Annots[ 11 0 R 12 0 R] /MediaBox[ 0 0 595.32 841.92]
/Contents 4 0 R/Group<</Type/G
Java

I have a piece of data that I am receiving in hexadecimal string
format, example: "65E0C8DEB69EA114567954". It was made this way in
C# by converting a byte array to a hexadecimal string. However, I am
using PHP to read this string and need to temporarily convert this
back to the byte array. If it matters, I will be decrypting this byte
array, then reconverting it to unencrypted hexadecimal and or
plaintext, but I will figure that out later.


So the
question is, how do I convert a string like the above back to an
encoded byte array/ blob in PHP?


Thanks!

C & C++ & C#

I have a hex string of 11 bytes
"0017333032CD4900186F41". I have to convert this string
to a byte array and I am doing it fine and getting the correct result.
However, following a particular message format, I would like to
convert this hex string to a byte array of size 16 instead of 11. Is
this possible?


I tried hex.getBytes("UTF-8")
and this gave me an array of size 32. Is it possible to have a 11 byte
hex string as a byte array of 16?


This requirement is in
Java for a BlackBerry app. This has been successfully implemented in
Android and iPhone. Android is making use of the
ByteConverter lib in Basic4Android

Programming Languages

I want to achieve something in my android application. I need to
create a HEX representation of a String variable in my class and to
convert it to byte array. Something like this :


String
hardcodedStr = "SimpleText";
String hexStr =
someFuncForConvert2HEX(hardcodedStr); // this should be the HEX
string
byte[] hexStr2BArray = hexStr.getBytes();
/>

and after that I want to be able to convert this
hexStr2BArray to String and get it's value. Something
like this :


String hexStr = new String(hexStr2BArray,
"UTF-8");
String firstStr = someFuncConvertHEX2Str(hexStr); //
the result must be : "Si
Java

I'm nead convert from hex String to byte array.
fo
example:
String str = "CAFF3E";
byte s[] = new
byte[3];
answer will be:
s[0] // CA
s[1] // FF />s[2] // 3e
Thank in advance!!!
Programming Languages

- Technology - Languages
+ Webmasters
+ Development
+ Development Tools
+ Internet
+ Mobile Programming
+ Linux
+ Unix
+ Apple
+ Ubuntu
+ Mobile & Tablets
+ Databases
+ Android
+ Network & Servers
+ Operating Systems
+ Coding
+ Design Software
+ Web Development
+ Game Development
+ Access
+ Excel
+ Web Design
+ Web Hosting
+ Web Site Reviews
+ Domain Name
+ Information Security
+ Software
+ Computers
+ Electronics
+ Hardware
+ Windows
+ PHP
+ ASP/ASP.Net
+ C/C++/C#
+ VB/VB.Net
+ JAVA
+ Javascript
+ Programming
Privacy Policy - Copyrights Notice - Feedback - Report Violation 2018 © BigHow