I am currently working on a custom SAPUI5 app. I would like to make a service call, which expects the Guid in a different format than it is currently available.
An example:
Available (base64): QvLAUUzUCZbhAAAAjSS2iA==
As it should be (hexadecimal): 42F2C0514CD40996E10000008D24B688
I have not found an online decoder, which could produce the desired result, however, I was able to encode the guid 42F2C0514CD40996E10000008D24B to QvLAUUzUCZbhAAAAjss2iA== with the SAP ABAP standard function module HTTP_BASE64_ENCODE. With the usual online encoders, however, I got a different result.
How can I decode the encoded guid with JavaScript so that it has the desired format?
The string is in hexadecimal format you will have to convert it.
First you convert the string to binary (atob > charCodeAt) and then using the toString(16) you get the hex.
I will not post the code, since its already explained
Decode Base64 to Hexadecimal string with javascript
Related
I am using SheetJS library to parse xlsx file with javascript.
The way i got the file force me to pass received data as string into the javascript function.
Now I confused how do i pass the string into XLSX.utils.sheet_to_txt. What type of convertion should I use?
The solution has found.
The string was converted to hex and converted back to array
As far as I know java uses UTF-16 to represent chars and string internally,
so if we load a text file from a file it is automatically decoded to its original encoding to utf-16.
Now the same can be said also for javascript
it also uses utf-16 as the internal string representation.
Suppose we load a string x encoded in utf-8 using ajax,
a converion takes place in order for javascript to be able to represent internally that string in UTF-16.
Please tell me if any of what I stated is correct or not,
because the real question is yet to come...
Now suppose the browser is rendering a page using utf-8 encoding,
and using javascript we want the browser to render also the ajax string x (as you normally do)
Would, in this case, a further conversion be needed from utf-16 to utf-8 ?
Thanks in advance.
According to this article, it is USC-2 or UTF-16
I'm trying to encrypt the following hash to base64:
6bb984727b8c8c8017207e54b63976dc42ea9d24ad33bd5feeaa66869b650096
It's needed to access the API of a website. The website shows an example script in JavaScript using the CryptoJS.enc.Base64.stringify() method to encrypt the hash.
The result with this method is
a7mEcnuMjIAXIH5Utjl23ELqnSStM71f7qpmhptlAJY=
However, every online base64 encryption tool I tried gives me the following result:
NmJiOTg0NzI3YjhjOGM4MDE3MjA3ZTU0YjYzOTc2ZGM0MmVhOWQyNGFkMzNiZDVmZWVhYTY2ODY5YjY1MDA5Ng==
I need to create the encoded string in C++. I've also already tried 4 different base64encode implementations (OpenSSL and custom codes), but also there I get the above result and the API always answers my string is not correctly encoded.
So where is the difference, and does somebody know a C++ implementation for CryptoJS.enc.Base64.stringify()?
Let's call
a = "6bb984727b8c8c8017207e54b63976dc42ea9d24ad33bd5feeaa66869b650096";
b = "a7mEcnuMjIAXIH5Utjl23ELqnSStM71f7qpmhptlAJY=";
c = "NmJiOTg0NzI3YjhjOGM4MDE3MjA3ZTU0YjYzOTc2ZGM0MmVhOWQyNGFkMzNiZDVmZWVhYTY2ODY5YjY1MDA5Ng==";
Both conversions are correct, but depend on what you actually want.
For example the following two equations hold
toBase64FromBytes(toBytesFromUtf8(a)) == c
toBase64FromBytes(toBytesFromHex(a)) == b
It's a bad idea to trust some kind of online calculator, because they usually don't disclose how they encode stuff, so you will get arbitrary results. If you program it yourself, you get the expected results if you follow the documentation.
I suspect you got a by printing a hash or encryption result to the console like this:
console.log(result.toString()); // a
Most result objects in CryptoJS are WordArray types. When you call the toString() function on such an object, you get a Hex-encoded string of that binary object.
If you print result.toString(CryptoJS.enc.Base64) then you get the Base64-encoded string of the binary result.
If you take a and directly encode it to Base64, then it is probably assumed that a is already a string (e.g. UTF-8 encoded). An online calculator doesn't know that it is Hex-encoded.
I am looking to take the contents of a file as a string (any file type), and convert that string into a string of Base64 solely using JavaScript for the purpose of outputting in a blob url. In many cases btoa() does not work, obviously due to it not accepting information that is not 8 bit. I need to be able to convert any string into a Base64 string. If this is possible, can someone please provide a solution?
I am trying to convert a small paragraph into a sequence of numbers (and maybe chars) like the md5 does.
I tried md5() in PHP and http://www.myersdaily.org/joseph/javascript/md5.js using JS but I get different result.
I do not know why this is happening, but can you suggest me a way to convert the text to a sequence of chars and numbers (to save them in DB) that will give me the same output? I do not mind if the output is not crypto.
Thank you
I would use the base64 encode/decode. Check out the link for the php http://php.net/manual/en/function.base64-encode.php and here is a link with some examples for javascript Base64 encoding and decoding in client-side Javascript
If you don't need crypto convert them into Hexadecimal value.
For example "Stack" will be 537461636B.
If you want to easily encrypt them, just use xor. This cannot give you different results in any possible language.
in PHP I found this function here PHP convert string to hex and hex to string
in JS I found some code here http://snipplr.com/view/52975/