How to convert Hex values to Base64 in Oracle? - oracle

I have the following string in Hex :
5B31E7C4931C2F62A4EB06573B3D4D4B7D96D2AAD05F9D626664CEB53023F1020F38B4399D98A2F280DC3606666B966A1B6878D2559044B2FC583FDFAB680714
I'm trying to convert it to Base64 using Oracle.
According to this calculator : https://base64.guru/converter/encode/hex the result should be
WzHnxJMcL2Kk6wZXOz1NS32W0qrQX51iZmTOtTAj8QIPOLQ5nZii8oDcNgZma5ZqG2h40lWQRLL8WD/fq2gHFA==
which is correct.
I tried the following computation but it doesn't return the correct value :
UTL_ENCODE.BASE64_ENCODE(HEXTORAW(Value))
Does anyone know how to achieve this in Oracle ?
Thanks.
Cheers,

UTL_ENCODE.BASE64_ENCODE returns a RAW. You want to turn it back to a string
utl_raw.cast_to_varchar2(UTL_ENCODE.BASE64_ENCODE('5B31E7C4931C2F62A4EB06573B3D4D4B7D96D2AAD05F9D626664CEB53023F1020F38B4399D98A2F280DC3606666B966A1B6878D2559044B2FC583FDFAB680714'))

Related

How to decode base64 & hexadecimal response from query

The query comes as
"returnData": [
"zWCLtKpUXZbkWNM9deAVPizTxXASOjX63ubdUHDN+vw=",
"zWCLtKpUXZbkWNM9deAVPizTxXASOjX63ubdUHDN+vw="
],
How can I decode that string? I can see it is decodable base64 first, but I get a very weird string after. Can someone show me the steps to follow to receive the decoded final string?
Base64 encodes binary data, which means if you send data that is not a string you won't be able to retrieve a string back. So to properly parse the return data you will need to know what data types were actually returned.
It might also be helpful to use a base64 to hex decoder first, so you get the hex representation of your data.
To give you more concrete recommendations we would need to know what data you expected, preferably showing the whole endpoint definition as well as any custom structs that might be involved.

how to decode an hexacidemal values to binary ones with springboot?

i am a new developper
i don't know how to decode hexacidemal values to binary ones with springboot, Is There a default functions That can help me or should i develop functions by myself
Also ,i want to compare the result with another one , should the 2 values be String ?
thank You
When you group 4 bits(1 bit is binary) it form a tuple which represent by one Hex decimal number.
There is no need of converting Hex to binary(in string format).
If you still want to do this you can refer:
https://www.geeksforgeeks.org/java-program-to-convert-hexadecimal-to-binary/

PLSQL - convert UTF-8 NVARCHAR2 to VARCHAR2

I have a table with a column configured as NVARCHAR2, I'm able save the string in UTF-8 without any issues.
But the application the calls the value does not fully support UTF-8.
This means that the string is passed to the database and back after the string is converted into HTML letter code. Each letter in the string is converted to such HTML code.
I'm looking for an easier solution.
I've considered converting it to BASE64, but it contains various characters which are considered illegal in the application.
In addition tried using HEXTORAW & RAWTOHEX.
None of the above helped.
If the column contains 'κόσμε' I need to find a way to convert/encode it to something else, but the decode should be possible to do from the HTML running the application.
Try using ASCIISTR function, it will convert it in something similar as JSON encodes unicode strings (it's actually the same, except "\" is used instead of "\u") and then when you receive it back from front end try using UNISTR to convert it back to unicode.
ASCIISTR: https://docs.oracle.com/cd/B28359_01/server.111/b28286/functions006.htm
UNISTR: https://docs.oracle.com/cd/B19306_01/server.102/b14200/functions204.htm
SELECT ASCIISTR(N'κόσμε') FROM DUAL;
SELECT UNISTR('\03BA\1F79\03C3\03BC\03B5') FROM DUAL;

storing data contains special characters in orientdb

WE are using Orient DB to store our data. In that we are storing that using Ruby hashes. But if any special characters come in hash values the it breaks hash structure and causes error whiles storing.
WE need some help on how we can escape hash values so that special character get converted into constants.
we are passing following hash to orient db and it causes error because addressLine1 contain special characters which breaks JSON format.
{
"addressLine1" =>"my address`~!#\#$%^&*()_ +=-{}|[]:\"';<>?/.,",
"addressLine2"=>"india",
"city"=>"bangalore",
}
One thing we can do is that escape all strings in hash and then pass it to orient db and again while reading we will unescape this. Please give optimal solution.
Trying this works:
insert into V content {
"addressLine1" : "my address`~!#\#$%^&*()_ +=-{}|[]:\"';<>?/.,",
"addressLine2":"india",
"city" : "bangalore"
}
Thank you Lvca. After upgrading orientdb to 1.7.8 version we are able to resolve issue.

NSLog but show the raw unicode string

For example, it prints below string:
"user_description" = "\U5efa\U5b50\Uff0c\U6b4c\U540e\Uff0c\U5c0f\U5e86\Uff0c\U5c0fKen\Uff0c\U8fd9\U4e9b\U90fd\U662f\U6211\U3002\U6211\U60f3\U505a\U7684\U5c31\U662f\Uff0c\U6253\U5f00\U53cc\U624b\Uff0c\U62e5\U62b1\U4f60\U3002";
any one know how to print the actual string instead these un-readable characters?
or do you know why this issue happen? how to avoid it? encoding?
I'm not sure how you print it out, or what type of string it is, but have you played with different types of format specifiers? Apple Doc

Resources